[转载]Spring配置文件详解一:
- <context:annotation-config/>
在基于主机方式配置Spring时,Spring配置文件applicationContext.xml,你可能会见<context:annotation-config/>这样一条配置,它的作用是隐式的向Spring容器注册
AutowiredAnnotationBeanPostProcessor,
PersistenceAnnotationBeanPostProcessor,
例如:
- 如果想使用@Autowired注解,需要在Spring容器中声明AutowiredAnnotationBeanPostProcessor
Bean。传统的声明方式:<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> - 如果想使用@PersistenceContext注解,需要在Spring容器中声明PersistenceAnnotationBeanPostProcessor
Bean。传统的声明:<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> - 如果想使用@Required注解,需要在Spring容器中声明RequiredAnnotationBeanPostProcessor
Bean。传统声明方式: <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> - 如果想使用@Resource、@ PostConstruct、@
PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。传统申明方式:
<bean class="org.springframework.beans.factory.annotation.CommonAnnotationBeanPostProcessor"/>
所以,如果按照传统声明一条一条去声明注解Bean,就会显得十分繁琐。
因此如果在Spring的配置文件中事先加上<context:annotation-config/>这样一条配置的话,那么所有注解的传统声明就可以被
忽略,即不用在写传统的声明,Spring会自动完成声明。
<context:component-scan base-package="com.xx"
/>
<context:component-scan/>的作用是让Bean定义注解工作起来,也就是上述传统声明方式。
它的base-package属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理。
值得注意的是<context:component-scan/>不但启用了对类包进行扫描以实施注释驱动
Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor
和 CommonAnnotationBeanPostProcessor),因此当使用
<context:component-scan/>
后,就可以将 <context:annotation-config/>
移除了。
[转载]Spring配置文件详解一:的更多相关文章
- Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径 Java编程 spring的配置文件applicationContext.xml的默 ...
- spring配置文件详解--真的蛮详细
spring配置文件详解--真的蛮详细 转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常 ...
- J2EE进阶(四)Spring配置文件详解
J2EE进阶(四)Spring配置文件详解 前言 Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程 ...
- spring配置文件详解以及beans:beans标签
第一行的意思就是你这个文件的默认schema为security,所以你的beans定义就需要加上前缀beans 一般的定义文件默认都是beans: 下面是spring配置文件的详解: 转自:http: ...
- Spring 配置文件详解 (以2.5为例)
转载自:http://blog.csdn.net/zzjjiandan/article/details/22922847 Spring配置文件是用于指导Spring工厂进行Bean生 ...
- Spring配置文件详解
转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常有用 spring配置文件是用于指导Sp ...
- Spring配置文件详解 - applicationContext.xml文件路径
spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...
- Spring配置文件详解:<context:annotation-config/>和<context:component-scan base-package=""/>和<mvc:annotation-driven />
<context:annotation-config/> 在基于主机方式配置Spring时,Spring配置文件applicationContext.xml,你可能会见<contex ...
- 【 spring配置文件详解】
转自: http://book.51cto.com/art/201004/193743.htm Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的 ...
随机推荐
- outlook撤回已发送邮件
官方教程参考: https://support.office.com/zh-cn/article/%E5%8F%91%E9%80%81%E9%82%AE%E4%BB%B6%E5%90%8E%E6%92 ...
- VS2012如何显示行号
Tools-Options-Text Editor-All Languages –General – Display
- docker desktop
https://github.com/rogaha/docker-desktop http://blog.csdn.net/tinylab/article/details/45443563
- h5 localStorage本地存储
用户名:<input type="text" id="txtname"/> 密码:<input type="text" i ...
- velocity 的 escape实现
EscapeHtmlReference的escape方法调用以下方法实现: StringEscapeUtils.escapeHtml(param); 再调用 org.apache.commons.la ...
- seaborn(matplotlib)画图,linux系统中文乱码等问题解决
data = pd.read_json(json.dumps(issue_dpl)) # set pic size plt.figure(figsize=(13, 5)) sns.set_style( ...
- Altera自带的RAM仿真学习
(1)单口RAM 1.无读使能rden信号的ModelSim功能仿真: 在不使用读使能rden信号的情况下,单口RAM仿真结果表明: 1.写使能wren为高时,写数据操作有效: 2.写使能wren为低 ...
- 剑指offer 面试17题
面试17题: 题目:打印从1到最大的n位数 题:输入数字n,按顺序打印出从1到最大的n位十进制数,比如输入3,则打印出1.2.3一直到最大的3位数999. 解题思路:需要考虑大数问题,这是题目设置的陷 ...
- 'is' in Python
在Python中应该避免将“is”运算符用于比较 像“数值”和“字符串”这种不可变的值.由于Python内部操作这些对象的方式,使得对这些对象使用“is”运算符的结果将是不可预测的. 下面以两个例子加 ...
- Java Web项目在Mac系统上启动时提示nodename nor servname provided
今天一不小心更新了Mac系统,然后在启动Java Web项目的时候,提示了java.net.UnknownHostException: MAC-mini-local nodename nor serv ...