Spring之BeanFactoryPostProcessor框架下PropertyPlaceholderConfigurer类
2016-07-27 09:32
477 查看
使用方式
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="configBean" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>hello.properties</value> </property> </bean> <bean id="helloBean" class="onlyfun.caterpillar.HelloBean"> <property name="helloWord"> <value>${onlyfun.caterpillar.helloWord}</value> </property> </bean> </beans>
其中hello.properties文件中的内容为:
onlyfun.caterpillar.helloWord=Welcome!
原理
其中PropertyPlaceholderConfigurer正是BeanFactoryPostProcessor的一个重要实现。Allows for custom modification of an application context’s bean definitions, adapting the bean property values of the context’s underlying bean factory.
A BeanFactoryPostProcessor may interact with and modify bean definitions, but never bean instances.
由此可见,BeanFactoryPostProcessor只能处理BeanDefinition; 是在所有Bean 实例化之前就执行的。
未完待续…
相关文章推荐
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring和ThreadLocal
- Spring Boot 开发微服务
- Spring AOP动态代理-切面
- Spring整合Quartz(JobDetailBean方式)
- Spring整合Quartz(JobDetailBean方式)
- 模拟Spring的简单实现
- Spring整合WebSocket应用示例(上)
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解
- 监听器获取Spring配置文件的方法
- Java利用Sping框架编写RPC远程过程调用服务的教程
- springmvc 发送ajax出现中文乱码的解决方法汇总
- Spring MVC中Ajax实现二级联动的简单实例
- SpringMVC框架下JQuery传递并解析Json格式的数据是如何实现的
- 详解Java的MyBatis框架和Spring框架的整合运用
- struts2 spring整合fieldError问题