Spring中的<context:annotation-config/>
来源:互联网 发布:神优化游戏 编辑:程序博客网 时间:2024/06/18 04:06
在配置Spring的配置文件中,会常见到< context:annotation-config/>,其实它的作用是向Spring容器中注册四个BeanPostProcessor,其四个分别为:
- AutowiredAnnotationBeanPostProcessor
- CommonAnnotationBeanPostProcessor
- PersistenceAnnotationBeanPostProcessor
- RequireAnnotationBeanPostProcessor
注册这四个的作用,就是为了让系统能够识别相应的注解
例如:
先使用@Autowired注解,就必须声明AutowiredAnnotationBeanPostProcessor的Bean,传统的声明方式为: <bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/>
若想使用@Resource、@PostConstruct、@PreDestroy等就必须声明CommonAnnotationBeanPostProcessor的Bean。
若想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
若想使用@Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。
这样用起来会很麻烦,所以spring给我们提供了<context:annotation-config/>
的简化配置方式,将自动完成声明。
在使用注解时,一般会配置扫描包路径选项:<context:component-scan basc-package="包名"/>
,该配置包含了自动注入上述processor的功能,因此当使用<context:component-scan/>
时,就可以将<context:annotation-config/>
移除。
- Spring中的<context:annotation-config/>
- Spring中的context:annotation-config作用
- 关于Spring中的<context:annotation-config/>配置
- Spring配置中的<context:annotation-config/>
- spring配置文件中的<context:annotation-config/>
- Spring配置中的<context:annotation-config/>
- 关于Spring中的<context:annotation-config/>配置
- Spring中的<context:annotation-config/>配置
- 关于Spring中的<context:annotation-config/>配置
- 关于Spring中的<context:annotation-config/>配置
- 关于Spring中的<context:annotation-config/>配置
- Spring中的<context:annotation-config/>配置
- 关于Spring中的<context:annotation-config/>配置
- 关于Spring中的<context:annotation-config/>配置
- Spring配置中的<context:annotation-config/>
- 关于Spring中的<context:annotation-config/>配置
- 关于Spring中的<context:annotation-config/>配置
- 关于Spring中的<context:annotation-config/>配置
- mysql上给表增加一个自增长列的脚本
- android布局及其常用属性
- Android系统 小米/三星/索尼 应用启动图标未读消息数(BadgeNumber)动态提醒
- ormlite的一对多详解
- 适配器模式及SDK源码中的运用(附:分别面向接口、类、对象的适配器扩展)
- Spring中的<context:annotation-config/>
- JVM之我们需要掌握的
- MyBatis学习(二) - SQL语句映射文件(1)resultMap
- android ndk NEON Support
- effective c++学习笔记
- manual make usb installer for windows in ubuntu15.04
- 关于更改Zend Studio/Eclipse代码风格主题的介绍
- 黑马程序员——Java基础---API(下)
- 7_13:验证longjmp后变量的值