Spring中的<context:annotation-config/>配置
来源:互联网 发布:大数据营销系统犯法吗 编辑:程序博客网 时间:2024/06/03 15:49
关于Spring中的<context:annotation-config/>配置
当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如:
使用@Autowired注解,必须事先在Spring容器中声明AutowiredAnnotationBeanPostProcessor的Bean:
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/>
使用 @Required注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean:
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
类似地,使用@Resource、@PostConstruct、@PreDestroy等注解就必须声明 CommonAnnotationBeanPostProcessor;使用@PersistenceContext注解,就必须声明 PersistenceAnnotationBeanPostProcessor的Bean。
这样的声明未免太不优雅,而Spring为我们提供了一种极为方便注册这些BeanPostProcessor的方式,即使用<context:annotation- config/>隐式地向 Spring容器注册AutowiredAnnotationBeanPostProcessor、RequiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor以及PersistenceAnnotationBeanPostProcessor这4个BeanPostProcessor。如下:
<context:annotation-config/>
另,在我们使用注解时一般都会配置扫描包路径选项:
<context:component-scan base-package="pack.pack"/>
该配置项其实也包含了自动注入上述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/>配置
- 软件评测师真题解答与分析7
- [Objective-C]__bridge,__bridge_retained和__bridge_transfer的意思,区别与使用
- 犀牛——第6章对象 6.1 创建对象
- Java中的UML关系(泛化,实现,依赖,关联(聚合,组合))
- CoreBluetooth之数据的读取与发送
- Spring中的<context:annotation-config/>配置
- Android,EditText,InuputType
- [iOS学习]关于UILabel计算多行高度以及显示的问题
- rtmp协议
- [android开发]ImageView\的getLayoutParams()和setLayoutParams()
- android 4.4以上可以实现的沉浸式状态栏效果
- TCP的keep-alive小结
- dataguard丢失归档案例
- vs2010打包过程