首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring读取属性资料

2012-09-03 
spring读取属性文件bean.xml: bean idpropertyConfigurer classBundlePropertiesLoader property

spring读取属性文件

bean.xml:
<bean id="propertyConfigurer" class="BundlePropertiesLoader">
<property name="bundlePropertyFileNames">
<list>
<value>test.properties</value>
</list>
</property>
</bean>

/**
* spring读取属性文件
*/
public class BundlePropertiesLoader extends PropertyPlaceholderConfigurer
{
??? public void setBundlePropertyFileNames( String[] fileNames )
??? {
??????? InputStream in = null;
??????? Properties pts = null;

??????? try
??????? {
??????????? // 读取spring文件中配置的属性文件名称
??????????? for ( String fileName : fileNames )
??????????? {
??????????????? in = BundlePropertiesLoader.class.getClassLoader()
??????????????????????? .getResourceAsStream( fileName );
??????????????? pts = new Properties();

??????????????? // 加载属性文件
??????????????? pts.load( in );
????????????? super.setProperties( pts );
??????????? }
??????? } catch ( Exception e )
??????? {??????
??????? }

????????finally

?????? {

????????? if (null != in)

???????? {

?????????????? in.close();

???????? }

?????? }
??? }

?

热点排行