开发者

Spring application context : access web.xml context-params?

Greetings ,

Is there any way to get values from web.xml context-param into Spring context?

For example I define the value in web.xml as :

<context-param>
  <param-name>compass-index</param-name>
  <param-value>file:///home/compass/index</param-value>
</context-param>

And I want to assign that value to the bean-property as:

<bean ...>
<props>
  <prop key="compass.engine.connection">
    ${from web.xml context-param?}
  </prop>
</开发者_StackOverflow社区props>
</bean>

Thanks in advance?


Yes - ServletContextPropertyPlaceholderConfigurer

This article explains the details. In short, you need:

<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>

and then use the properties like:

<bean ...>
   <property name="compassIndex" value="${compass-index}" />
</bean>

or with @Value("${compass-index}")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜