0

Hi I'm using Spring PropertyPlaceholderConfigurer to fetch values from a properties file.

It's working when i get the value in xml. but in a java class

@Value("${application.imagesPath}")
private String imagesPath;

Returns the literal value "${application.imagesPath}" even though when running the server if the variable application.imagesPath is not in the properties file i get the error

Could not autowire field: private java.lang.String com.ymobility.filltrack.controller.ApiController.imagesPath; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'application.imagesssPath' in string value

(the typo imagesssPath is on purpose to show that if i misspell it, it is knowing that the property doesn't exist which indicates that it is actually reading the properties file correctly, my issue is when there is no error, the value retrieved is the literal string "${application.imagesPath}" instead of it's value in properties file)

So the controller is actually getting the value from the properties file, but the value of the string when used is still the literal value "${application.imagesPath}".

My context.xml file contains the following config

<bean id="appProperties"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>/WEB-INF/properties/app.properties</value>
        </list>
    </property>
</bean>

The class I'm using has the following annotations

@RestController
@RequestMapping("/api")

Any idea what might be the problem ?

Thanks

Dany Y
  • 6,833
  • 6
  • 46
  • 83
  • Can you show the configs ? Also, is this variable inside a managed bean? – dambros Apr 15 '16 at 18:34
  • I edited my answer, the fact that when i misspell the property name i get an error means that it's actually reading the properties file correctly no ? – Dany Y Apr 15 '16 at 18:37
  • 1
    'application.imagesssPath' ... maybe a typo? – cproinger Apr 15 '16 at 18:37
  • the typo is on purpose to show that if i misspell it, it is knowing that the property doesn't exist which indicates that it is actually reading the properties file correctly, my issue is when there is no error, the value retrieved is the literal string `"${application.imagesPath}"` instead of it's value in properties file – Dany Y Apr 15 '16 at 18:39
  • Your config looks wrong. It should be using `org.springframework.context.support.PropertySourcesPlaceholderConfigurer`. Can you try this config please? – dambros Apr 15 '16 at 18:43
  • still, same output, I'm actually using data from the properties file for the database connection, and it's working (but it's from an xml file) so i think the issue is in my java controller – Dany Y Apr 15 '16 at 18:54
  • possible duplicate of http://stackoverflow.com/questions/11890544/spring-value-annotation-in-controller-class-not-evaluating-to-value-inside-pro – DwB Apr 15 '16 at 19:47

0 Answers0