Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Using PropertyPlaceholderConfigurer to read in external properties - not working

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

We need to use an external properties file (not in the classpath, not bundled with our WAR/EAR) & these properties need to be used to set some spring bean properties. This is exactly described in a 2008 blog post at ('Optional External Properties'). I tried using the technique in an example but I get the error that the property that I reference from the external file is not being set.

1) spring bean xml file (TestSpringProp is my own Spring bean that I'm testing this example with; it has setMyProp and getMyProp methods):
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true"/>
<property name="location" value="${PropFile}"/>

<bean id="TestSpringProp" class="com.att.testspring.TestSpringProp">
<property name="myProp" value="${test.myprop}" />

2) I create C:\deploy\ as follows:

3) I then run it from Eclipse with the JVM argument as follows: -DPropFile=C:\deploy\

4) I don't get any errors on the 2 PropertyPlaceholderConfigurer beans but I get an error when I try to access the property that's in my property file: "Invalid bean definition with name 'TestSpringProp' defined in class path resource [config/spring/testspring.xml]: Could not resolve placeholder 'test.myprop'
Why fit in when you were born to stand out? - Seuss. Tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic