annotation-driven,annotation-config,component-scan的区别与作用
http://blog.csdn.net/ac_great/article/details/47665831
<mvc:annotation-driven />与<context:annotation-config />
https://www.cnblogs.com/dreamroute/p/4493346.html
总结
<mvc:annotation-driven />
mvc打头的主要是给spring mvc用的
会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean
是spring MVC为@Controllers分发请求所必须的。
并提供了这些注解:路径映射@RequestMapping 数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)。
<context:annotation-config>
declares support for general annotations such as @Required, @Autowired, @PostConstruct, and so on.
他的作用是式地向 Spring 容器注册
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。
是对包进行扫描,实现注释驱动Bean定义,同时将bean自动注入容器中使用。即解决了@Controller标识的类的bean的注入和使用。
<context:component-scan/>
配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,
同时还启用了注释驱动自动注入的功能(即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor),
因此当使用 <context:component-scan/> 后,
除非需要使用PersistenceAnnotationBeanPostProcessor和equiredAnnotationBeanPostProcessor两个Processor的功能(例如JPA等)
否则就可以将 <context:annotation-config/> 移除了。
有的乱,反正就是写了component-scan就能用spring的大部分注解了,不用写上面俩了
浙公网安备 33010602011771号