Reputation: 6391
Suppose I have this in my application.yml
file:
spring:
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
- ..... <other exclusions>
Then, in application-redis.yml
profile I want to re-enable this auto-configuration.
What I could do apart from copying the whole list without just one entry?
Please don't suggest the solutions based on code modification (like specific annotations etc. - I need to do it with properties only). Also, I cannot make this auto-configuration enabled initially and add some kind of the "default" profile where it's disabled.
Upvotes: 1
Views: 3065
Reputation: 13281
@Configuration
.@Profile("redis")
.@Import(RedisAutoConfiguration.class)
.Done! Looks like:
package com.my.package;
import org.springframework.context.annotation.*;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
@Configuration
@Profile("redis")
@Import(RedisAutoConfiguration.class)
// config more here...
class MyRedisConfig {
// ..or here
}
...this will re-import the application.yaml
-excludes (for RedicAutoConfig class only), when activating "redis" profile.
Not sure whether this is "quicker", than the copy&paste approach, but sounds exactly what, configuration+import+profile were "designed for"!;)
If a
@Configuration
class is marked with@Profile
, all of the@Bean
methods and@Import
annotations associated with that class will be bypassed unless one or more of the specified profiles are active
Upvotes: 2