Reputation: 15802
In my xml configuration files I can write
<context:component-scan base-package="com.my.stuff"/>
Now I move on java based configuration. How I can do it in my @Configuration
based class without having ApplicationContext
there?
Upvotes: 5
Views: 3594
Reputation: 665
In case of spring < 3.1 you can use http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.html in @PostConstruct method of your @Configuration class. Of course you need to autowire ApplicationContext into you @Configuration.
Upvotes: 3
Reputation: 16158
You can use @ComponentScan annotation to your configuration class.
Example :
@Configuration
@ComponentScan("com.acme.app.services")
public class AppConfig {
@Bean
public MyBean myBean() {
// instantiate, configure and return bean ...
}
}
Upvotes: 15