spring中的PropertyPlaceholderConfigurer类
来源:互联网 发布:java 金额转换成大写 编辑:程序博客网 时间:2024/05/16 14:49
PropertyPlaceholderConfigurer类的主要的用法是将BeanFactory里定义的内容放在一个.properties的文件中.
比如,本来BeanFactory(设BeanFactory的配置文件名字为spring.xml)中的代码为
使用PropertyPlaceholderConfigurer类后可以改成
而config.properties的内容为
当然,仅仅这样还不够,因为框架不会无缘无故创建你的propertyConfigurer类,因此还需要在web.xml中配置一下,代码如下:
通过以上的操作,我们可以将一些属性的配置放到了properties文件中(由于PropertyPlaceholderCOnfigurer是在其他bean实例化之前进行的,所以对于项目中所有bean的配置,他们的属性值都可以是properties文件中的内容,很强大有木有?)
比如,本来BeanFactory(设BeanFactory的配置文件名字为spring.xml)中的代码为
<bean id="" class=""> <property name="user"> <value>liming</value> </property> <property name="password"> <value>123456</value> </property></bean>
使用PropertyPlaceholderConfigurer类后可以改成
<bean id="propertyConfigurer" class="org.springframework.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:config.properties</value> <list> </property></bean>
而config.properties的内容为
user=limingpassword=123456
当然,仅仅这样还不够,因为框架不会无缘无故创建你的propertyConfigurer类,因此还需要在web.xml中配置一下,代码如下:
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:spring.xml</param-value></context-param><listener><listener-calss>org.springframework.web.context.ContextLoaderListener</listener-calss></listener>
通过以上的操作,我们可以将一些属性的配置放到了properties文件中(由于PropertyPlaceholderCOnfigurer是在其他bean实例化之前进行的,所以对于项目中所有bean的配置,他们的属性值都可以是properties文件中的内容,很强大有木有?)
0 0
- spring中的PropertyPlaceholderConfigurer类
- spring中的PropertyPlaceholderConfigurer
- Spring - XML中的PropertyPlaceholderConfigurer
- [Spring]PropertyPlaceholderConfigurer类相关
- spring之PropertyPlaceholderConfigurer类
- spring中的PropertyPlaceholderConfigurer作用,用法
- spring中的PropertyPlaceholderConfigurer作用、用法
- spring中的PropertyPlaceholderConfigurer作用,用法
- Spring框架下PropertyPlaceholderConfigurer类
- Spring框架下PropertyPlaceholderConfigurer类
- Spring框架下PropertyPlaceholderConfigurer类
- Spring类PropertyPlaceholderConfigurer的作用
- Spring框架下PropertyPlaceholderConfigurer类
- Spring类PropertyPlaceholderConfigurer的作用
- spring中的PropertyPlaceholderConfigurer访问properties文件配置
- Spring--PropertyPlaceholderConfigurer
- spring propertyplaceholderconfigurer
- Spring PropertyPlaceholderConfigurer
- Hibernate映射的问题
- Hive安装
- LCM 常用寄存器和resume方式
- spring中获取配置文件内容
- 使用Plink -ssh与Linux交互
- spring中的PropertyPlaceholderConfigurer类
- android:layout_gravity和android:gravity的区别
- QEMU-KVM
- 【技术分享】基于浏览器的指纹识别技术(含缓解方案)
- 中英文混合排序
- html:表单和表单提交
- KVM配置文件注释
- ubuntu14.04搭建网关服务器和DHCP服务器
- JAVA并发-并发编程概述