Jerry Z.
Jerry Z.

Reputation: 2051

Spring @Value Could not resolve placeholder in string value

Have the context spring conf like this, I have 2 property-placeholder in my context.

<?xml version="1.0" encoding="UTF-8"?>
<beans>
    <context:annotation-config/>
    <context:component-scan base-package="com.xxx.app.xxx"/>

    <context:property-placeholder location="classpath:em-management.properties"/>
    <context:property-placeholder location="file:///opt/ass/swp/conf/platform.properties"/>

</beans>

When I run the code, met this error:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CMClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.xxxx.app.xxxx.xx.client.CMClient.washost; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'com.ibm.CORBA.securityServerHost' in string value "${com.ibm.CORBA.securityServerHost}"

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.xxxx.app.xxx.xxx.client.CMClient.washost; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'com.ibm.CORBA.securityServerHost' in string value "${com.ibm.CORBA.securityServerHost}"

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'com.ibm.CORBA.securityServerHost' in string value "${com.ibm.CORBA.securityServerHost}"

how to solve this issue?

Upvotes: 1

Views: 10247

Answers (2)

Arpit Aggarwal
Arpit Aggarwal

Reputation: 29276

Don't use multiple <context:property-placeholder/> tags, refer below code for the same and also make sure you have a key "com.ibm.CORBA.securityServerHost" with a value in either of your property file.

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="location">
      <list>
         <value>classpath:em-management.properties</value>
         <value>file:///opt/ass/swp/conf/platform.properties</value>
      </list>
   </property>
   <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

Upvotes: 1

Jerry Z.
Jerry Z.

Reputation: 2051

I found the solution for this particular problem,just append ignore-unresolvable="true" to each line.

<context:property-placeholder location="classpath:em-management.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="file:///opt/ass/swp/conf/platform.properties" ignore-unresolvable="true"/>

Upvotes: 2

Related Questions