In Spring, getting "java.lang.IllegalArgumentException: Could not resolve placeholder" despite having defined "PropertyPlaceholderConfigurer"

Dave picture Dave · May 26, 2016 · Viewed 13.1k times · Source

I’m using Spring 3.2.11.RELEASE with Maven 3.3. I have this defined in my application context file …

<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>

but when I run my test, I get the below error

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}"

This is baffling me because in my target/classes directory, I can see a file, “quickbase.properties,” that has the “quickbase.username” defined. I can’t figure out what else I need to check.

Answer

Chaos Legion picture Chaos Legion · May 12, 2017

I received similar error today. I resolved it by adding a little space between the dollar and first brace {. I believe java runtime is trying to resolve an unintended placeholder. Following is the example:

<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>