Search code examples
springspring-mvcspring-roo

Inject property into autowired class


Using Roo, and I've got a property called 'imagesBaseDir' in a property file called app.properties, and should be getting picked up by this:

<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>

I want to push this property into a controller, so I've put a field in there like this (as per all the examples I have read)

private @Value("${imagesBaseDir}") String imageBaseDir;

But it's not getting set.

Tried it with other properties from e.g. db.properties, which I know Spring is definitely picking up, so my props file is probably ok.

What am I missing? Driving me nuts, all the examples looks so straightforward but it's just not working for me :(

Thanks!


Solution

  • You are having a child context (dispatcher-servlet.xml) and you are trying to inject the value in a controller that's defined there. However, child contexts don't get the properties resolved with <context:prop.... You need to have that in dispatcher-servlet.xml as well.