配置Spring <context:annotation-config/>的作用
来源:互联网 发布:使命召唤10怎么优化 编辑:程序博客网 时间:2024/05/17 12:52
隐式在基于注解方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>
这样一条配置,他的作用是式地向 Spring 容器注册
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。
例如:
如果你想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。传统声明方式如下
<bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/>
如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor
如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
如果想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。同样,传统的声明方式如下:
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
一般来说,这些注解我们还是比较常用,尤其是Antowired的注解,在自动注入的时候更是经常使用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供<context:annotation-config/>
的简化配置方式,自动帮你完成声明。
不过,呵呵,我们使用注解一般都会配置扫描包路径选项
<context:component-scan base-package=”XX.XX”/>
该配置项其实也包含了自动注入上述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/>配置
- phpstorm集成phpunit
- iOS学习笔记(十七)——文件操作(NSFileManager)
- 拷贝PDF中文字出现英文乱码的问题
- js实现获取当前时间,并一直刷新
- linux下mysql自动dump
- 配置Spring <context:annotation-config/>的作用
- Oracle 执行计划(Explain Plan) 说明
- WPF中DataGrid设置列头样式
- 绘制音量调节视图
- MonGo入门指南,示例
- 安卓基础——adb相关内容
- Hashmap遍历的两种方式
- fdk-aac-0.1.4编译
- Matlab to OpenCV Mat