Spring中<context:annotation-config/>的作用
来源:互联网 发布:石油天然气文献数据库 编辑:程序博客网 时间:2024/05/17 10:27
最近在研究Spring中<context:annotation-config/>配置的作用,现记录如下:
<context:annotation-config/>的作用是向Spring容器注册以下四个BeanPostProcessor:
- AutowiredAnnotationBeanPostProcessor
- CommonAnnotationBeanPostProcessor
- PersistenceAnnotationBeanPostProcessor
- RequiredAnnotationBeanPostProcessor
是为了让系统能够识别相应的注解。
例如:
1、如果想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。
传统声明方式如下:<bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/>
2、如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor Bean。
3、如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
4、如果想使用@Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。
以上这些注解是很常用的,如果按照传统的方式进行配置将会非常繁琐,所以Spring给我们提供了一个简便的方式:<context:annotation-config/>,使用该元素可以自动声明以上注解。
注:由于<context:component-scan base-package=”xx.xx”/>也包含了自动注入上述Bean的功能,所以<context:annotation-config/> 可以省略。如果两者都进行了配置,则只有前者有效。
注:
<context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注解。
<context:component-scan>除了具有<context:annotation-config>的功能之外,<context:component-scan>还可以在指定的package下扫描以及注册javabean 。
- 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/>
- [NOTE] Oracle官网JDK下载路径(持续更新)
- 第17章 ioctl操作
- Intellij IDEA 出现“Usage of API documented as @since 1.7+”的解决办法
- test
- 问题排除:RecyclerView添加分割线后,每次下拉刷新 Item与分割线间都会增加间距。
- Spring中<context:annotation-config/>的作用
- ios 随机数生成
- RabbitMQ(三)——Publish/Subscribe
- apply和call的区别
- vim实用插件(目录树、代码补全、颜色主题等)
- git warning: refname 'HEAD' is ambiguous
- CentOS配置postgresql+postsql
- 开源在线考试系统
- Wannafly挑战赛2【solved : 2 / 5】