I'm using Spring MVC. In a Controller class, I want to use the @Value annotation to inject a value that comes from a properties file:
@Value("${upload.dir}")
private String uploadDir;
So I need to put a property-placeholder somewhere.
The web.xml is typical:
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/mvc-dispatcher-servlet.xml</param-value>
</init-param>
...
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/business-context.xml</param-value>
</context-param>
First, I put the placeholder in business-context.xml. It doesn't work: "Could not autowire field".
Then I put it in mvc-dispatcher-servlet.xml, it works.
So I'm confused about these two contexts, are they the same one or different? Because the beans I defined in business-content.xml can be autowired, but the @Value doesn't work.
I don't want to put the placeholder in both xml files 'cause I have a long 'location' property. Also the business-context.xml will be used by some jobs, so it cannot be omitted.
Any way to make placeholder defined in business-context.xml become visible in mvc-dispatcher-servlet.xml as well?