Spring应用程序上下文:访问web.xml context-params?

时间:2010-02-01 08:43:16

标签: java spring web.xml

问候,

有没有办法从web.xml context-param中获取值到Spring上下文?

例如,我将web.xml中的值定义为:

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

我想将该值分配给bean-property:

<bean ...>
<props>
  <prop key="compass.engine.connection">
    ${from web.xml context-param?}
  </prop>
</props>
</bean>

提前致谢?

1 个答案:

答案 0 :(得分:25)

是 - ServletContextPropertyPlaceholderConfigurer

This article解释了细节。简而言之,您需要:

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

然后使用以下属性:

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

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