Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在属性占位符配置器中使用EL时发生Spring错误_Java_Spring_Properties - Fatal编程技术网

Java 在属性占位符配置器中使用EL时发生Spring错误

Java 在属性占位符配置器中使用EL时发生Spring错误,java,spring,properties,Java,Spring,Properties,我试图从类路径中加载一个属性文件值,以在属性占位符configurers locations属性中解析,其想法是,我可以根据从类路径文件加载的值加载外部属性文件。。。。举个例子可能会让这更容易理解 1) 从类路径加载一些属性 <bean id="globalProperties" class="common.config.ServletContextPropertyPlaceholderConfigurer"> <property name="key" value="g

我试图从类路径中加载一个属性文件值,以在属性占位符configurers locations属性中解析,其想法是,我可以根据从类路径文件加载的值加载外部属性文件。。。。举个例子可能会让这更容易理解

1) 从类路径加载一些属性

<bean id="globalProperties" class="common.config.ServletContextPropertyPlaceholderConfigurer">
    <property name="key" value="globalProperties" />
    <property name="ignoreResourceNotFound" value="true" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="locations">
        <list>              
            <value>classpath:application.properties</value>                 
        </list>
    </property>
</bean>

PropertyPlaceHolder不是按顺序加载和应用的,它们都是一次加载的。您只能使用从环境中可用的变量,而不能使用从属性文件中加载的变量。好的,谢谢,那就清楚了@贝林布洛:你最后找到解决办法了吗?是否可以在第二个占位符中使用另一个占位符的属性?我也尝试了PropertyOverrideConfiguler,但运气不好。嗨@我做得很好,但这并不是你真正想要的解决方案。在M.Deinum的回复后,我与托管团队达成协议,总是从${user.home}加载在linux生产服务器上始终是/home/tomcat,在我的本地机器上,我创建了一个C:\\home\tomcat,它仍然在本地解析为/home/tomcat。我不认为这将帮助你,虽然,对不起!谢谢你的回答。但是的,这不是我正在寻求的解决方案。
<bean id="appProperties" class="common.config.ServletContextPropertyPlaceholderConfigurer">
    <property name="key" value="appProperties" />
    <property name="ignoreResourceNotFound" value="true" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="locations">
        <list>              
            <value>file:#{globalProperties['app.config']}/app.config.properties</value>
            <value>file:${user.home}/app.config.properties</value>
            <value>file:${user.dir}/app.config.properties</value>
        </list>
    </property>
</bean>
    Error creating bean with name 'appProperties' defined in ServletContext resource [/WEB-INF/config/properties.xml]: 
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; 
nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos 16): Indexing into type 'common.config.ServletContextPropertyPlaceholderConfigurer' is not supported