转载自:http://blog.sina.com.cn/s/blog_872758480100wtfh.html
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向
AutowiredAnnotationBeanP
PersistenceAnnotationBea
注册这4个
例如:
如果你想使用@Autowired注解,那么就必须事先在
<bean
如果想使用@ Resource
如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBea
如果想使用
<bean
一般来说,这些注解我们还是比较常用,尤其是Antowired的注解,在自动注入的时候更是经常使用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供<context:annotation-config/>的简化配置方式,自动帮你完成声明。
<context:component-scan
<context:annotation-config />
<!-- 扫描注解Bean -->
<context:component-scan base-package="com.ddd">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>