你好,
有没有办法从 web.xml 上下文参数中获取值到 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>
提前致谢?
最佳答案
是的 - ServletContextPropertyPlaceholderConfigurer
This article解释细节。简而言之,您需要:
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>
然后使用如下属性:
<bean ...>
<property name="compassIndex" value="${compass-index}" />
</bean>
或使用 @Value("${compass-index}")
关于java - Spring 应用程序上下文 : access web. xml 上下文参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2175502/