James
James

Reputation: 1237

How to use context-param defined in web.xml in dispatcher servlet?

I have a very small concern, to which I couldn't find an answer even after Googling for quite sometime.

How do we use context-param defined in web.xml in the dispatcher servlet?

In my web.xml, I have defined it like this:

<context-param>
    <param-name>root.path</param-name>
    <param-value>/root</param-value>
</context-param>

I can access it in my Java class using the below lines of code:

String rootPath = sce.getServletContext().getInitParameter("root.path");

However, I don't see a way to use this value in dispatcher servlet. I want to use a variable for /root in the below case than the value itself.

<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="file:/root/main.properties" />

Any help is highly appreciated.

Thank you.

Upvotes: 2

Views: 3264

Answers (1)

Pranav Kevadiya
Pranav Kevadiya

Reputation: 539

Try using

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:location="file:/#{contextParameters.root.path}/main.properties" />

This will create problem if we give name as "root.path", instead give name as "root_path"

Upvotes: 3

Related Questions