Spring对于注解的扫描

对于这两个配置Spring中已经作出了很明确的说明html

<context:annotation-config/>java

(The implicitly registered post-processors include AutowiredAnnotationBeanPostProcessorCommonAnnotationBeanPostProcessor,PersistenceAnnotationBeanPostProcessor, as well as the aforementioned RequiredAnnotationBeanPostProcessor.)spring

<context:annotation-config/> only looks for annotations on beans in the same application context in which it is defined. This means that, if you put<context:annotation-config/> in a WebApplicationContext for a DispatcherServlet, it only checks for @Autowired beans in your controllers, and not your services. See Section 17.2, “The DispatcherServlet” for more information.api

The use of <context:component-scan> implicitly enables the functionality of <context:annotation-config>. There is usually no need to include the<context:annotation-config> element when using <context:component-scan>.app

结论:也就是说当咱们使用<context:component-scan>的时候就不须要再使用<context:annotation-config>了post

相关文章
相关标签/搜索