问候,
有没有办法从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>
提前致谢?
答案 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}")