我正在尝试使用 Spring PropertyPlaceHolder 加载一组属性,该属性在 Tomcat 和 Weblogic 上都能正常工作。现在我将其更改为加载文件夹中的所有属性文件,它在 Tomcat 中运行良好,但在 Weblogic 上运行不佳。
你能帮我看看哪里出了问题吗
这是我在 XML 中更改的代码片段
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:${environment.config}*.properties
</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="false" />
</bean>
使用 Weblogic,它无法找到 key ,因此应用程序未加载。
Using
Spring 4.1.5
Tomcat 8
Weblogic : 10.3.6
我也尝试添加 org.springframework.beans.factory.config.* 在 weblogic.xml 中,但没有帮助。
最佳答案
我使用 applicationcontext.xml 中的 *.properties 自定义了属性文件的加载。我扩展了“PropertiesFactoryBean”并初始化了类,并从下面的文件夹中读取了所有属性
public static List<Properties> loadAllProperties() {
File[] files = new File(System.getProperty("environment.config")).listFiles();
List<Properties> lstOfProperties = new ArrayList<>();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
String filename = file.getName();
String extension = filename.substring(filename.lastIndexOf(".") + 1, filename.length());
if (("properties").equals(extension)) {
Properties props = new Properties();
try {
props.load(new FileReader(file));
} catch (IOException e) {
LOGGER.error("Loading Properties " , e);
}
lstOfProperties.add(props);
}
}
}
}
return lstOfProperties;
}
然后使用 PropertiesFactoryBean 的“setPropertiesArray”和“mergeProperties”这两个方法,我在加载时将所有必需的属性添加到系统。
可能还有更好的选择,但这对我有用,可能对其他人有帮助。
关于java - 通过在 Weblogic 中不起作用的文件夹在 Spring 应用程序中加载多个属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33416776/