spring-bootspring-profilesspring-autoconfiguration

How to disable auto configuration when test profile in @SpringBootApplication?


Are there elegant ways to prevent AutoConfigure configuration classes when certain profile (e.g. test) in use? I've all configs in my tests, and don't wanna mark every config in main folder with @Profile("!test")

there also is: @SpringBootApplication(exclude=****Configuration.class) possibility but it's for class, not for profile.


Solution

  • What I did (but not for test) its to disable the AutoConfigure via properties file when a certain profile is enabled.

    For instance, I don't want Redis to be auto-configured when profile "withoutRedis" is enabled (dev purpose). I created a property file "application-withoutRedis.properties" and its content :

    spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration