Spring框架中Spring配置文件中<context:annotation-config/>标签说明
<context:annotation-config/>此标签的重要作用就是:
省去系统繁琐的注解标签,加上一个此标签,就可以在此项目程序添加“注解”的功能,使系统识别相应的注解功能!!
详解:
<context:annotation-config/>标签的作用是隐式地向 Spring 容器注册AutowiredAnnotationBeanPostProcessor、
CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这4个BeanPostProcessor。
注册这4个 BeanPostProcessor的作用,就是为了让系统能识别相应的注解。
比如系统繁琐的注解功能:
1:如果使用@Autowired注解:
必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。传统声明方式如下
<bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/>
2:如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor
3:想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
4:想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。
即:<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
总结:这些注解我们还是比较常用,尤其是Antowired的注解,在自动注入的时候更是经常使用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供的简化配置方式,自动帮你完成声明。-----即用<context:annotation-config/>标签即可;
附加:使用注解一般还要用到扫描包路径的选项:<context:component-scan base-package=”XX.XX”/>
最新文章
- 如何在ubuntu里面关掉后台的meteor
- role roleMapping 权限说明
- tinyxml学习2
- 【Machine Learning】机器学习の特征
- DIV JS CSS 轻量级弹出层 兼容各浏览器
- The remote SSH server rejected X11 forwarding request
- mysql使用经验总结
- source insight 支持CC 文件
- Swift - 10 - assert(断言)
- python Tkinter 全屏显示
- oracle分区表运行计划
- httpclient总结
- C# 语言规范_版本5.0 (第0章 目录)
- 【反编译系列】一、反编译代码(dex2jar + jd-gui)和反编译资源(apktool)
- fjwc2019 D6T2 密文(trie+贪心)
- 第 8 章 容器网络 - 055 - 创建 macvlan 网络
- css3种引入方式,样式与长度颜色,常用样式,css选择器
- ubuntu 16.04 LTS 修改 国内源(以中科大源为例)
- linux /proc/pid进程信息说明
- 温故而知新-WebSocket 教程
热门文章
- Docker实战部署应用——MySQL5.7
- srs-librtmp pusher(push h264 raw)
- 2018-9-21-dot-net-core-使用-usb
- git flow工作流
- V7双雄-基于Virtex7XC7VX690T的高性能计算板卡解决方案
- java调用sqlldr报错:Message 2100 not found
- 7——C++类的使用
- python面向对象--类和实例的认识
- 前端每日实战:93# 视频演示如何用纯 CSS 创作一根闪电连接线
- Cobaltstrike系列教程(二)-Listner与Payload生成 heatlevel