对于这两个配置Spring中已经做出了很明确的说明
<context:annotation-config/>
(The implicitly registered post-processors include , ,, as well as the aforementioned .)
<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.
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>
.
结论:也就是说当我们使用<context:component-scan>的时候就不需要再使用<context:annotation-config>了