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();
???????? }
?????? }
??? }
?