我想在项目中加载一个属性:
<beans>
...
<context:annotation-config />
<bean id="properties_es"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:/texts/report_es.properties" />
</bean>
<bean id="properties_en"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:/texts/report_en.properties" />
</bean>
</beans>
然后我尝试同时获得两个.properties
public class PropertiesManager {
public static enum LanguageEnum{es, en}
@Autowired
private java.util.Properties properties_es;
@Autowired
private java.util.Properties properties_en;
public String getProperty(LanguageEnum language, String key) {
switch (language) {
case es:
return properties_es.getProperty(key);
case en:
return properties_en.getProperty(key);
default:
return properties_en.getProperty(key);
}
}
}
但 properties_es和properties_en有系统信息,如:{file.encoding.pkg = sun.io,com.sun.enterprise.appname = j2ee,com.sun.aas.useNewClassLoader = true, ...}而不是文件.properties
中定义的信息