在Spring中,尽管已经定义了"PropertyPlaceholderConfigurer",但获取"java.lang.IllegalArgumentException:无法解析占位符"

Dav*_*ave 1 spring properties applicationcontext property-placeholder

我正在使用Spring 3.2.11.RELEASE和Maven 3.3.我在我的应用程序上下文文件中定义了这个...

<bean id="localPropertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="locations">
        <list>
            <value>classpath:quickbase.properties</value>
        </list>
        </property>
</bean> 
…
<bean id=“myClient" class="org.mainco.subco.mysystem.MyClient">
    <constructor-arg index="0" type="String" value="${quickbase.username}" />
    <constructor-arg index="1" type="String" value="${quickbase.password}" />
    <constructor-arg index="2" type="String" value="${quickbase.url}" />
</bean>
Run Code Online (Sandbox Code Playgroud)

但是当我运行我的测试时,我得到以下错误

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myClient' defined in class path resource [META-INF/spring/applicationContext-orders.xml]: Could not resolve placeholder 'quickbase.username' in string value "${quickbase.username}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'quickbase.username' in string value "${quickbase.username}"
Run Code Online (Sandbox Code Playgroud)

这让我感到困惑,因为在我的target/classes目录中,我可以看到一个文件"quickbase.properties",它定义了"quickbase.username".我无法弄清楚我还需要检查什么.

Cha*_*ion 9

我今天收到了类似的错误.我通过在美元和第一个支撑之间增加一点空间来解决它.我相信java运行时正试图解决一个非预期的占位符.以下是示例:

<bean id=“myClient" class="org.mainco.subco.mysystem.MyClient">
    <constructor-arg index="0" type="String" value="$ {quickbase.username}" />
    <constructor-arg index="1" type="String" value="$ {quickbase.password}" />
    <constructor-arg index="2" type="String" value="$ {quickbase.url}" />
</bean>
Run Code Online (Sandbox Code Playgroud)