對於這兩個配置Spring中已經作出了很明確的說明html
<context:annotation-config/>java
(The implicitly registered post-processors include AutowiredAnnotationBeanPostProcessor
, CommonAnnotationBeanPostProcessor
,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