Reputation: 1475
I have a class AppConfig annotated with @Configuration which is having various bean definitions which includes beans which performs a third party hit from the application. now in my spring integration test cases, I do not want these beans to be initialized. that is where I created an another bean with name TestAppConfig annotated with @Configuration where I have mocked all those beans which performs third party hit. now in my testContext.xml I am adding an exclude filter to context:component-scan where I am specifying the AppConfig package to be excluded. but somehow this AppConfig is being initialized everytime. I have tried proper regex, but still things are not working. if anyone know the cause then please share.
Upvotes: 0
Views: 1157
Reputation: 2447
After see the comment that you are using spring 3.2, you can see here for older version of spring to use @Profile
You can use @Profile annotation to determine which @Bean will be created or not.
Example:
Defined Beans are below
@Bean
@Profile("production")
public DataSource prodDataSource() {
...
return dataSource;
}
@Bean
@Profile("development")
public DataSource devDataSource() {
...
return dataSource;
}
For profile called "development"
spring.profiles.active=development
prodDataSource
will not be called. But devDataSource
will be calledFor profile called "production"
spring.profiles.active=production
prodDataSource
will not be called. But devDataSource
will be calledUpvotes: 2