public Properties loadFrameworkProperties(String path)
{
Properties result = new Properties();
try
{
result.load(getClass().getClassLoader().getResourceAsStream(path));
}
catch(IOException e)
{
System.err.println((new StringBuilder()).append("Load application properties file failed : ").append(path).toString());
e.printStackTrace();
}
return result;
}
//spring方式加载
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="propertyConfigurer" class="com.xxx"> <property name="locations">
<list>
<value>classpath:server.properties</value>
</list>
</property>
</bean>
</beans>
{
Properties result = new Properties();
try
{
result.load(getClass().getClassLoader().getResourceAsStream(path));
}
catch(IOException e)
{
System.err.println((new StringBuilder()).append("Load application properties file failed : ").append(path).toString());
e.printStackTrace();
}
return result;
}
//spring方式加载
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="propertyConfigurer" class="com.xxx"> <property name="locations">
<list>
<value>classpath:server.properties</value>
</list>
</property>
</bean>
</beans>