开发者

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

开发者 https://www.devze.com 2022-12-18 11:48 出处:网络
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 :

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

精彩评论

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