Spring 3.05- issue with @Value - returning null

1.6k views Asked by At

@Value is returning null as I am trying to read properties.

Below is my configuration:

<util:properties 
     id="applicationProps"
     location="/WEB-INF/spring/application.properties" />

Below is the code that I have in a custom tag:

private @Value("#{applicationProps.staticResourceUrl}") String staticResourceUrl;
2

There are 2 answers

0
blank On

Custom tag lifecycle is not usually handled by spring but one thing you can do is extend

org.springframework.web.servlet.tags.RequestContextAwareTag

and do

WebApplicationContext wac = getRequestContext().getWebApplicationContext();
String url = wac.getEnvironment().getProperty("some.property");

in the doStartTagInternal() method.

7
Paul McKenzie On

If the props file application.properties contained a property called staticResourceUrl then import it via:

 <context:property-placeholder location="/WEB-INF/spring/application.properties"/>

and use it via:

@Value("${staticResourceUrl}") private String staticResourceUrl;