Spring - JavaConfig with Component Scan

To configure Spring container with our beans, we can mix XML's <context:component-scan> with JavaConfig configuration. We can even avoid XML altogether by using @ComponentScan. There too we can mix the factory approach along with scan approach. In factory approach we annotate classes with @Configuration having methods annotated with @Bean which return bean instances). For component scanning to work we must annotate our beans with one of the stereotype annotations

  1. Component
  2. Controller
  3. Repository
  4. Service

Classes annotated with one of the above are candidate for spring container registration when using scanning. The most important is Component annotation. 

要查看或添加评论,请登录

?? Saral Saxena ???????的更多文章

社区洞察

其他会员也浏览了