Spring中加载属性文件

 在SPRING中提供了一个专门加载属性文件的类,我们只要给它指定属性文件所在的路径即可。这样我们就可以把一些经常变化的配置放入特定的属性文件中。下面为该类在SPRING中的配置:

  1.     <bean id="propertyConfigurer"       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  2.         <property name="location">
  3.             <value>classpath:com/starxing/test/database.properties</value>
  4.         </property>
  5. <!-- 使用locations属性定义多个配置文件
  6.        <property name="locations">
  7.             <list>
  8.                 <value>classpath:config/mail.properties</value>
  9.                 <value>classpath:config/database.properties</value>
  10.             </list>
  11. </property>
  12. -->
  13. </bean>
  1. <bean id="dataSource"
  2.         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  3.         <property name="url">
  4.             <value>${database.url}</value>
  5.         </property>
  6.         <property name="driverClassName">
  7.             <value>${database.driver}</value>
  8.         </property>
  9.         <property name="username">
  10.             <value>${database.user}</value>
  11.         </property>
  12.         <property name="password">
  13.             <value>${database.password}</value>
  14.         </property>
  15. </bean>

database.properties

database.driver=org.postgresql.Driver
database.url=jdbc:postgresql://localhost/test
database.user=postgres
database.password=123456
propertyConfigurer加载database.properties文件,为创建dataSource提供参数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值