java - 如何将我的 spring xml 配置移到我的 web 应用程序之外?

标签 java spring web-applications

如何将我的 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 from WEB-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/

相关文章:

java - 如何在jsp中显示日期,如 "2017-08-30 14:35:43"

java - Hibernate JPA 序列(非 Id)

spring - 访问被拒绝(用户是匿名的);重定向到身份验证入口点

javascript - 在 JavaScript 中以 Ajax 发布数组数据并在服务器端读取参数

java - 在 weblogic 12.1.3 C 中部署 webservice 的问题?

Java "Printer is not accepting jobs"老兄弟打印机

java - 使用deployJava.js在javascript中调用java方法

html - 在 th :href link 中使用模型属性

java - Spring 注入(inject)时向servlet过滤器添加in-it参数

web-services - 这是网络服务的良好候选者吗?