Spring配置文件读取properties文件中的value

<bean id="propertyConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<list>

<value>classpath*:/jdbc.properties</value>

<value>classpath*:/mail.properties</value>

</list>

</property>

<property name="fileEncoding" value="utf-8" />

<property name="placeholderPrefix" value="$[" />

<property name="placeholderSuffix" value="]" />

</bean>

定义上面的bean之后,就可以再xml文件中通过name提取properties文件中的值,例如:

<bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName">

<value>$[db.driver]</value>

</property>

<property name="url">

<value>$[db.url]</value>

</property>

<property name="username">

<value>$[db.username]</value>

</property>

<property name="password">

<value>$[db.password]</value>

</property>

</bean>

猜你喜欢

转载自longcxm.iteye.com/blog/1847647