我有一个非常小的担忧,即使在谷歌搜索很长一段时间后我也找不到答案。
我们如何在调度程序 servlet 中使用 web.xml 中定义的 context-param?
在我的 web.xml 中,我这样定义它:
<context-param>
<param-name>root.path</param-name>
<param-value>/root</param-value>
</context-param>
我可以使用以下代码行在我的 Java 类中访问它:
String rootPath = sce.getServletContext().getInitParameter("root.path");
但是,我没有找到在调度程序 servlet 中使用此值的方法。在下面的情况下,我想使用/root 的变量而不是值本身。
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="file:/root/main.properties" />
非常感谢任何帮助。
谢谢。
最佳答案
尝试使用
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="file:/#{contextParameters.root.path}/main.properties" />
如果我们将名称指定为“root.path”,而不是将名称指定为“root_path”,则会产生问题
关于spring - 如何在调度程序 servlet 中使用 web.xml 中定义的 context-param?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15290849/