Spring应用程序上下文:访问web.xml context-params? [英] Spring application context : access web.xml context-params?
本文介绍了Spring应用程序上下文:访问web.xml context-params?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候,
有没有办法从web.xml context-param中获取值到Spring上下文?
Is there any way to get values from web.xml context-param into Spring context?
例如,我将web.xml中的值定义为:
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>
我想将该值分配给bean属性:
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>
</props>
</bean>
提前致谢?
推荐答案
是 - ServletContextPropertyPlaceholderConfigurer
Yes - ServletContextPropertyPlaceholderConfigurer
本文解释了详细信息。简而言之,您需要:
This article explains the details. In short, you need:
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>
然后使用以下属性:
<bean ...>
<property name="compassIndex" value="${compass-index}" />
</bean>
或 @Value($ {compass-index})
这篇关于Spring应用程序上下文:访问web.xml context-params?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文