如何将我的 spring xml 配置移到我的 java web 应用程序之外?
我想将我的 spring.xml 存储在我的 Web 应用程序之外,这样我就不必创建我的应用程序的新版本来更改配置。
执行此操作的最佳方法是什么?
最佳答案
正如 Rod Johnson 在 this thread 中解释的那样:
You can use the
classpath:
prefix to load from the classpath, with the normal Spring listener or startup servlet. This is made possible by Spring's Resource abstraction. You can freely mix and match resources fromWEB-INF
and classpath.
因此,将配置文件放在 webapp 之外的类路径中的某个位置,并在 web.xml
中声明以下内容:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springContext*.xml</param-value>
</context-param>
我认为依赖类路径比使用绝对文件路径更可移植。
关于java - 如何将我的 spring xml 配置移到我的 web 应用程序之外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1456621/