Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring应用程序上下文:访问web.xml上下文参数?_Java_Spring_Web.xml - Fatal编程技术网

Java Spring应用程序上下文:访问web.xml上下文参数?

Java Spring应用程序上下文:访问web.xml上下文参数?,java,spring,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> 罗盘指数 file:///home/compas

您好

有没有办法将web.xml上下文参数中的值输入到Spring上下文中

例如,我将web.xml中的值定义为:

<context-param>
  <param-name>compass-index</param-name>
  <param-value>file:///home/compass/index</param-value>
</context-param>

罗盘指数
file:///home/compass/index
我想将该值指定给bean属性,如下所示:

<bean ...>
<props>
  <prop key="compass.engine.connection">
    ${from web.xml context-param?}
  </prop>
</props>
</bean>

${from web.xml context param?}
提前谢谢?

是的-

解释细节。简而言之,您需要:

<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>

然后使用如下属性:

<bean ...>
   <property name="compassIndex" value="${compass-index}" />
</bean>


从Spring 3.1开始,使用
@Value(“${compass index}”)

的ServletContextPropertyPlaceHolderConfigure已被弃用(有关详细信息,请参阅javadocs)。谢谢。因此,看看spring文档中特别“酷”的功能中的弃用说明,事实上已经提到了弃用,但没有提供更新的示例代码。@Askar Kalkov文档对您必须做的事情不是很清楚,但最终它实际上相当简单。请参阅此答案:这似乎是正确的XML,因为ServletContextPropertyPlaceHolderConfigure已被弃用: