Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I move my spring xml configuration outside of my web application?

How do I move my spring xml configuration outside of my java web application?

I'd like to store my spring.xml outside of my web application so I don't have to create a new build of my application to change the configuration.

What is the best way to do this?

like image 316
ScArcher2 Avatar asked Sep 21 '09 20:09

ScArcher2


1 Answers

As Rod Johnson explains it in 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.

So, put the configuration files somewhere in the classpath outside the webapp and declare the following in the web.xml:

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:springContext*.xml</param-value>
</context-param>

I think that relying on the classpath is more portable than using an absolute file path.

like image 76
Pascal Thivent Avatar answered Nov 06 '22 21:11

Pascal Thivent