微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 如何在我的Web应用程序之外移动spring xml配置?

如何在我的java Web应用程序之外移动spring xml配置?

我想将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中声明以下内容

aram>
  aram-name>contextConfigLocationaram-name>
  aram-value>classpath:springContext*.xmlaram-value>
aram>

我认为依赖类路径比使用绝对文件路径更便携.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐