xml文件:<context:annotation-config/>
2016-06-12 10:23
190 查看
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。
例如:
如果你想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。传统声明方式如下:
<span style="font-size:14px;"><span style="white-space:pre"> </span><bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProces
4000
sor "/></span>
如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。
<span style="font-size:14px;"><span style="white-space:pre"> </span><bean class="org.springframework.beans.factory.annotation. CommonAnnotationBeanPostProcessor "/></span>
如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
<span style="font-size:14px;"><span style="white-space:pre"> </span><bean class="org.springframework.beans.factory.annotation.PersistenceAnnotationBeanPostProcessor "/></span>
如果想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。同样,传统的声明方式如下:
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。
例如:
如果你想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。传统声明方式如下:
<span style="font-size:14px;"><span style="white-space:pre"> </span><bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProces
4000
sor "/></span>
如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。
<span style="font-size:14px;"><span style="white-space:pre"> </span><bean class="org.springframework.beans.factory.annotation. CommonAnnotationBeanPostProcessor "/></span>
如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
<span style="font-size:14px;"><span style="white-space:pre"> </span><bean class="org.springframework.beans.factory.annotation.PersistenceAnnotationBeanPostProcessor "/></span>
如果想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。同样,传统的声明方式如下:
<span style="font-size:14px;"><span style="white-space:pre"> </span><bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/></span>一般来说,这些注解我们还是比较常用,尤其是Antowired的注解,在自动注入的时候更是经常使用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供<context:annotation-config/>的简化配置方式,自动帮你完成声明
<span style="font-size:14px;"><span style="white-space:pre"> </span><context:annotation-config/></span>
相关文章推荐
- IOS Dev Intro - Notification Series 02
- Android Studio中如何获取sha1证书指纹数据debug.keystore
- IOS Dev Intro - Notification Series 01
- c debug.h
- 关于传递参数时,涉及数组的length = sizeof(a)/sizeof(int)还是为length = sizeof(a)的总结
- IOS Dev Intro - Key-Value Observing
- 【Linux】进程控制块PCD结构(tack_struct)
- 程序集重用
- Memcached是什么?【小强性能培训学员作品】
- IOS Dev Intro - Blocks Programming Series 06
- ajax+php实现自动提示文本框
- 我与【51CTO学院三周年有陌生到相爱】
- 五、centos 学习笔记
- yii框架中使用cookie和session
- IOS Dev Intro - Blocks Programming Series 05
- xcode7 上传APPStore错误ERROR ITMS-90474: iPad Multitasking support requires these orientations
- Application 与 全局变量 :
- bash on windows
- I.MX6 sdio 设备注册及识别
- IOS Dev Intro - Blocks Programming Series 04