0

I'm using spring 3.0 and trying to load a properties file:

<context:property-placeholder location="classpath:myFile.properties" />
...
<property name="userName" value="${myVariable}" />

...

Using a xpto.properties, when I try to use any parameter from this file if shows me the error:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myBean' defined in class path resource [myApplicationContext.xml]: Could not resolve placeholder 'myVariable'...

The strange thing is if I use file with the very specific name jdbc.properties it works! I searched for any reference or filter of jdbc.properties in my project and found nothing.

ps. one important thing: properties file is in the classpath, the error is not to load the file, it is when I trying to use any variable from this file (except if file name is jdbc)

Can someone give me a light?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • did you add classpath:your properties file name – Ramesh Kotha Feb 18 '13 at 20:29
  • I just tried to use it and I got the same error. What I'm actually using is – user2084661 Feb 18 '13 at 21:47
  • 1
    But you need to first register the `propety-placeholder` with spring container.http://www.baeldung.com/2012/02/06/properties-with-spring/. Go through this website.It will be helpful to you to understand how to use `propety` files in spring. – SRy Feb 19 '13 at 01:48
  • Are the `property-placeholder` and the `${myVariable}` in the same XML file or in different ones? – Ryan Stewart Feb 19 '13 at 01:56
  • Is `myVariable` defined in `xpto.properties`? Or is it just defined in `jdbc.properties`? – pap Feb 19 '13 at 11:03
  • It worked now! There project depend on another parent project and the placeholder was already defined in this parent (as jdbc.properties). So I only have to change parent. I didn't find before because this parent project was closed in eclipse when I tried to search. Thanks everybody for the help. – user2084661 Feb 19 '13 at 21:27

1 Answers1

1

It worked now! There project depend on another parent project and the placeholder was already defined in this parent (as jdbc.properties). So I only have to change parent. I didn't find before because this parent project was closed in eclipse when I tried to search. Thanks everybody for the help