---
spring:
config.activate.on-profile: nosecurity
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
- org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
---
spring:
config.activate.on-profile: noredis
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
if noredis,nosecurity active
expected: 1. org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration 2. org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration 3. org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
actual: 1. org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration 2. org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
Comment From: wilkinsona
Thanks for the suggestion but this is working as designed and documented. Please see https://github.com/spring-projects/spring-boot/issues/12444#issuecomment-372410949 for links to a number of issues with further discussion on the matter.
Comment From: quaff
@wilkinsona I know it's designed, my request is treat spring.autoconfigure.exclude specially and document it, such use case is very common, please reconsider. or guide me how to separate autoconfigure exclusions to multiple profiles.
Comment From: wilkinsona
That wasn’t clear to me from your original description which showed expected behaviour that is contrary to the documentation. That read like a bug report to me. A little bit of time explaining what you already now and what you are trying to do (rather than how you are trying to do it) would have been very helpful.
We can’t make an exception for this one property. It would be confusing for it to behave differently and would break for anyone relying on the current behaviour.
You haven’t really described what you are trying to do so offering advice is tricky. You could perhaps use the classpath to control which auto-configuration is active. Alternatively, as described in the issues linked to above, you can use some repetition in your configuration files. You would combine this with a profile expression such as noredis & nosecurity. If this becomes unwieldy you could also consider some logic in your main method or an environment post-processor the determines everything to exclude and sets the property.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
Comment From: gavenkoa
I faced with the same issue when attempted to modularize config: during local development I want selectively disable features via profiles, like no-redis, no-email, no-gcp-pubsub, etc.
Naive attempt was:
---
spring.config.activate.on-profile: no-redis-cache
spring.autoconfigure.exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
- org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration
---
spring.config.activate.on-profile: no-gcp-pubsub
spring.autoconfigure.exclude:
- org.springframework.cloud.gcp.autoconfigure.core.GcpContextAutoConfiguration
- org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubAutoConfiguration
If two profiles are active only one exclude takes place, see #12444
To archive the goal of joint exclusions I used the feature introduced in #12586, see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes#auto-configuration-exclusion
public class SaPubSubConfiguration {
@Configuration
@Profile("no-gcp-pubsub")
@ImportAutoConfiguration(
exclude = {
org.springframework.cloud.gcp.autoconfigure.core.GcpContextAutoConfiguration.class,
org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubAutoConfiguration.class,
})
public static class DisabledConfig { }
@Configuration
@Profile("!no-gcp-pubsub")
public static class EnabledConfig {}
}
public class RedisCacheManagerConfiguration {
@Configuration
@Profile("no-redis-cache")
@ImportAutoConfiguration(
exclude = {
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration.class,
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration.class,
})
public static class DisabledConfig { }
@Configuration
@Profile("!no-redis-cache")
@EnableCaching
public static class EnabledConfig { }
}
Comment From: gavenkoa
When debugging of exclude set breakpoint in AutoConfigurationImportSelector.selectImports():
Set<String> allExclusions = this.autoConfigurationEntries.stream()
.map(AutoConfigurationEntry::getExclusions).flatMap(Collection::stream).collect(Collectors.toSet());