I'm developing a spring-boot webapp which has the following package structure..
- com.myname.configs
- CommonConfiguration.java
- DevConfiguration.java
- ProdConfiguration.java
- SomeOtherConfiguration.java
- com.myname.profiles
- DevProfile.java
- ProdProfile.java
All of these classes are @Configuration classes but the DevProfile.java and ProdProfile.java also have the @Profile and @Import annotations.
CommonConfiguration..
@Configuration
public class CommonConfiguration {
//commmon configs / beans..
}
DevConfiguration..
@Configuration
@Profile("dev")
public class DevConfiguration {
@Bean
//dev specific beans..
}
DevProfile..
@Configuration
@Import(value = {CommonConfiguration.class, DevConfiguration.class})
@Profile("dev")
public class DevProfile {}
ProdProfile..
@Configuration
@Import(value = {CommonConfiguration.class, ProdConfiguration.java})
@Profile("prod")
public class ProdProfile {}
For some reason, even with -Dspring.profile.active=prod, the beans for DevConfiguration are created. The only workaround is to add a @Profile("dev") annotation to DevConfiguration.java
Is there a way to only create the beans for classes in the @Import annotations? It seems logical to manage the Imports in one Profile class than add the Profile to various Configuration classes.
I'm looking for a way to do what @Aaron Digulla suggested in #1 here How to exclude some @Configuration file in Spring?