在spring中使用properties文件

如何在spring中使用配置文件呢?

以前觉得很神奇,写ibatis和spring整合的时候发现可以用PropertiesFactoryBean来导入properties配置,使用占位符来应用,真是太神奇了。

在spring2.0后貌似简化了,使用util的标签就可以到入,貌似换汤不换药。。

  1. <bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean">  
  2.   <property name="location" value="classpath:com/foo/jdbc-production.properties"/>  
  3. </bean>

新的方式:

  1. <util:properties id="jdbcConfiguration" location="classpath:com/foo/jdbc-production.properties"/> 

id一定要设置,不然bean就找不到了。。。

有篇更详细的介绍:http://www.javaeye.com/topic/24613

原文地址:https://www.cnblogs.com/xiziyin/p/1664880.html