Java 找不到具有多个上下文的属性:属性占位符

Java 找不到具有多个上下文的属性:属性占位符,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,我正在使用Spring3.1和spring配置文件来加载bean。在我的应用程序上下文文件中,我加载如下属性: <context:property-placeholder order="1" location="classpath*:META-INF/spring/*_${spring.profiles.active}.properties" ignore-unresolvable="true"/> 我的分析是,它试图在从第一个上下文属性占位符解析属性之前加载数据源。我可能错了。

我正在使用Spring3.1和spring配置文件来加载bean。在我的应用程序上下文文件中,我加载如下属性:

<context:property-placeholder order="1"  location="classpath*:META-INF/spring/*_${spring.profiles.active}.properties" ignore-unresolvable="true"/>
我的分析是,它试图在从第一个上下文属性占位符解析属性之前加载
数据源。我可能错了。或者可能是spring profile变量未正确解析

谁能帮我修一下吗

谢谢
Akki

既然您建议对配置文件的路径进行硬编码,请尝试使用标记上的profiles属性有选择地包括配置

<beans profile="profileName">
    <context:property-placeholder  order="1"  location="classpath*:META-INF/spring/hardcoded.properties" ignore-unresolvable="true"/>
</beans>

<beans profile="profileName2">    
    <context:property-placeholder order="1"  location="classpath*:META-INF/spring/hardcoded.properties" ignore-unresolvable="true"/>
</beans>


请参阅本文解释配置文件:

在我的应用程序中,我以以下方式使用属性占位符配置器,它工作得非常好。你可以试试


classpath*:META-INF/spring/*.${spring.profiles.active}.properties
我认为这应该能解决你的问题

每个都创建一个新的PropertyPlaceHolderConfigure实例-它很容易变得混乱。每个应用程序和应用程序级别上都应该有一个这样的东西,而不是库级别上的,这使得维护更加容易

有关更多详细信息以及如何应对的建议,请参见:

有关多个属性占位符的此错误可能与您的问题有关:

将多个
属性PlaceHolderConfiguration
@Value
注释和占位符语法的默认值(即
${key:defaultValue}
),只有第一个
属性PlaceHolderConfigure
是 用过。如果此配置器不包含所需的值,则会下降 返回到
@Value
默认值,即使第二个
PropertyPlaceHolderConfigure
包含该值

影响版本:3.1.3


尝试将订单设置为0否。它不起作用。我第一次将订单更改为0,但仍然有相同的错误。哦,等等,找不到数据库驱动程序。你把它添加到类路径了吗?是的。如果我去掉另外两个标签,它就会起作用。我认为它无法解析属性${database.drivercassname},如果我删除另外两个标记,它就会工作。它无法解析属性我猜其他两个属性占位符是否指定了顺序?@user1517723
commonconfigurationFactoryBean
如何发挥作用?当我从数据库加载属性时,它从org.apache.commons.configuration.DatabaseConfiguration创建属性对象。这将在内部使用数据源specified@user1517723我甚至在任何地方的文档中都找不到这个东西,我确实在这里找到了一个论坛帖子,说Spring3.x不支持它:但是引入了
order
属性来解决这个问题(而不是创建一个新的实例重用和维护一系列属性源)。目前正在开放。
<bean id="configFactoryBean"
class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
   <constructor-arg ref="globalSystemConfiguration"/>
</bean>
java.lang.ClassNotFoundException: ${database.driverClassName}
<beans profile="profileName">
    <context:property-placeholder  order="1"  location="classpath*:META-INF/spring/hardcoded.properties" ignore-unresolvable="true"/>
</beans>

<beans profile="profileName2">    
    <context:property-placeholder order="1"  location="classpath*:META-INF/spring/hardcoded.properties" ignore-unresolvable="true"/>
</beans>