If you are not mixing XML and Java configuration, can you use @Profile in a bean that can contain the @ComponentScan annotation with your target package?
Similarly with XML: you can have two different <beans ...> sections, each with a different profile, and in each section you define your own <context:component-scan basePackage="..." />
@Configuration @Profile("profile1") @ComponentScan(basePackage="package1") class Config1 { } @Configuration @Profile("profile2") @ComponentScan(basePackage="package2") class Config2 { }
source share