首页 > 其他 > 详细

<context annotation-config />标签意义

时间:2016-09-05 20:41:12      阅读:133      评论:0      收藏:0      [点我收藏+]
<context annotation-config />标签意义:
该标签隐式的向Spring容器注册了:
AutowiredAnnotationBeanPostProcessor   CommondAnnotationBeanPostProcessor
PersistenceAnnotationBeanPostProcessor   RequiredAnnotationBeanPostProcessor这四个BeanPostProcessor.
1.AutowiredAnnotationBeanPostProcessor:主要是使用@AutoWired注解时,必须提前向Spring容器注册这个BeanPostprocessor
传统的配置方式:<bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/>
2.CommondAnnotationBeanPostprocessor:主要是使用@Resource、@PostConstruct、@Predestory等注解时,必须提前向Spring容器注册。
传统配置方式:<bean class="org.springframework.beans.factory.annotation.CommondAnnotationBeanPostprocessor"/>
3.PersistenceAnnotationBeanPostProcessor :主要是使用@PersistenceContext注解时,必须提前向Spring容器注册。
传统配置方式:<bean class="org.springframework.beans.factory.annotation.PersistenceAnnotationBeanPostProcessor"/>
4.RequiredAnnotationBeanPostProcessor:主要是使用@Required注解时,必须提前向Spring容器注册。
传统配置方式:<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
一般来说,@Autowired注解比较常用,传统配置方式有点繁琐,而这种隐式配置方式就可以帮我们很容易的搞定。
不过使用注解,我们一般都会配置扫描包路径:<context: component-scan base-package=com.xxx.xxx />
其实,该配置已经包含了自动注入上述Processor的功能,所以,配置了包扫描之后,<context annotation-config />就可以移除了。

<context annotation-config />标签意义

原文:http://www.cnblogs.com/shuo1208/p/5843392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!