读书人

spring配备中调用properties文件

发布时间: 2012-09-10 22:20:12 作者: rapoo

spring配置中调用properties文件

system.properties


database.url=jdbc:mysql://localhost/smaple
database.driver=com.mysql.jdbc.Driver
database.user=root
database.password=root

2.applicationContext.xml


<?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="propertyConfigurer"

????? value="classpath:example4/helloworld.properties"/>
</bean>

helloworld.properties:
fileHelloWorld.statusname=this is status Name;

如果少了${fileHelloWorld.statusname}中少了Bean名称fileHelloWorld,会导致错误发生
这应该是种强制某个配置是属性某个Bean

3.PropertyPlaceholderConfigurer的配置不需要考虑Bean的名称,直接配置就可以了
配置方式和PropertyOverrideConfigurer类似

读书人网 >软件架构设计

热点推荐