How to access <context-param> values of web.xml in Spring Controller
spring
Solution
If you are using Spring 3.1+, you don't have to do anything special to obtain the property. Just use the familiar ${property.name} syntax.
For example if you have:
<context-param>
<param-name>property.name</param-name>
<param-value>value</param-value>
</context-param>
in `web.xml` or
`<Parameter name="property.name" value="value" override="false"/>`
in Tomcat's `context.xml`
then you can access it like:
@Component
public class SomeBean {
@Value("${property.name}")
private String someValue;
}
This works because in Spring 3.1+, the environment registered when deploying to a Servlet environment is the StandardServletEnvironment that adds all the servlet context related properties to the ever present `Environment`.
Problem
I am defining a context-param in web.xml of my application as below ``` <context-param> <param-name>baseUrl</param-name> <param-value>http://www.abc.com/</param-value> </context-param> ``` Now i want to use the value of baseUrl in my Controller, so how i can access this.....? Please tell me if anyone knows about this. Thanks in advance !