java - 通过在 Weblogic 中不起作用的文件夹在 Spring 应用程序中加载多个属性文件

标签 java spring spring-mvc tomcat weblogic-10.x

我正在尝试使用 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/

相关文章:

java - 为什么我不能不等待就将 int 从 java 发送到 C?

java - jOOQ - 重用 SelectConditionStep

java - appCtx 中的多个事务遇到 NoUniqueBeanDefinitionException

java - 如何在没有 xml 的 Spring MVC 中启用 REST gzip 压缩?

java - Spring Security 问题 - 404 错误

java - 分享时将标题文字加粗

java - 使用 Spring boot 在 ConstraintValidator 中 Hibernate 验证对象

java - 来自属性文件的 Spring Hibernate 自定义 validator 默认消息

java - 如何使用 Hibernate MySQL Maven Spring MVC 显示数据库中的所有行

java - Spring , Spring MVC : Migrate XML configuration to Java giving data source not found error