BeanDefinitionStoreException:在文件中定义了名称为'aefw.propertyValues'的无效bean定义。...无法解析占位符'configRoot'

时间:2019-03-14 08:49:41

标签: java spring property-placeholder

这是我的spring配置文件,如下所示,

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="aefw.application" parent="aefw.applicationBase">
        <property name="configId" value="CHCPMTSP"/>
        <property name="configRoot" value="file:///C:/GIT/CHCPMTSP/CHCPMTSP/CHCPMTSP-web/src/main/resources/CHCPMTSP/config"/>
    </bean>

    <bean id="aefw.propertyValues" parent="aefw.props">
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="locations">
            <list>
                <value>${configRoot}/application.properties</value>
            </list>
        </property>
    </bean>
</beans>

我想添加新的属性文件,以便可以从控制器中的@Value批注中获取值,因此我正在更改配置文件以使用属性占位符,如下所示:

 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

        <bean id="aefw.application" parent="aefw.applicationBase">
            <property name="configId" value="CHCPMTSP"/>
            <property name="configRoot" value="file:///C:/GIT/CHCPMTSP/CHCPMTSP/CHCPMTSP-web/src/main/resources/CHCPMTSP/config"/>
        </bean>
        <context:property-placeholder location="classpath*:common.properties"/>

        <bean id="aefw.propertyValues" parent="aefw.props">
            <property name="ignoreUnresolvablePlaceholders" value="true" />
            <property name="locations">
                <list>
                    <value>${configRoot}/application.properties</value>
                </list>
            </property>
        </bean>
    </beans>

然后我遇到错误了,

BeanDefinitionStoreException: Invalid bean definition with name 'aefw.propertyValues' defined in file [C:\GIT\WS\CHCPMTSP\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\CHCPMTSP-web\WEB-INF\classes\app-context\beans-application.xml]: Could not resolve placeholder 'configRoot'

请提出一个更好的解决方案,这样我就可以在另一个bean中使用configRoot并在另一个文件中初始化property-placefolder。

检查现有答案无济于事,我还尝试在同一bean aefw.propertyValues中创建属性文件。 aefw.props指向propertyPlaceholder bean。

0 个答案:

没有答案