Spring应用程序上下文:访问web.xml中上下文PARAMS?
题
问候,
有没有办法摆脱的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 ...>
<props>
<prop key="compass.engine.connection">
${from web.xml context-param?}
</prop>
</props>
</bean>
在预先感谢?
解决方案
是 - ServletContextPropertyPlaceholderConfigurer
此文章解释的细节。总之,你需要:
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>
和然后使用性能,如:
<bean ...>
<property name="compassIndex" value="${compass-index}" />
</bean>
或与@Value("${compass-index}")
不隶属于 StackOverflow