java - Spring 应用程序上下文 : access web. xml 上下文参数?

标签 java spring web.xml

你好,

有没有办法从 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/

相关文章:

java - android同步隐藏状态栏

Spring 自定义过滤器总是被调用

具有多个登录页面的 Spring 安全性

jsp - 如何在 Windows tomcat 中部署在 RHEL 5 中制作的 java tomcat 项目?

java - web.xml的<filter-mapping>里面的<servlet-name>是什么意思?

java - 使用 Hibernate Criteria 进行不区分大小写的排序

java - jbuttons 和具有 Action 监听器的 jtextfield

spring - 在 web.xml 中将 BasicDataSource 配置为 bean

java - java中如何改变字符串的字体?

java - 无法访问 spring boot 执行器的/beans