Where to place spring configuration files when using maven

I am trying to solve my problems with configuration files.

I have a Spring MVC application with this structure (my current structure)

  src / main / java / ....................... (java classes)
 src / main / resources / .................. (some .properties files)
 src / main / webapp / ..................... (web content, web.xml)
 src / main / webapp / spring / .............. (other spring config files, app-confix.xml, etc.)
 src / main / webapp / myApp-servlet.xml .... (servlet config)


 src / test / java ........................ (java test classes)
 src / test / resources ................... (some test .properties files) 

(this is a pretty standard maven project directory structure)

So, and my question is: Should I put Spring configuration files in the resource directory or not? I am not sure that they can be considered as resource files. Most Spring projects have a configuration in the WEB-INF / directory. But there is one problem with unit testing, because when I need to load the servlet configuration, then maven expects the configuration files in the / test / resources directory. I know that I can copy the context xml file into the tested class, and everything will be fine, but it does not look so good for me.

I have read many articles on the Internet, but I'm still not sure if this is the right way.

So, I have tree options:

1. stay with the current structure

2. move the entire Spring configuration to / main / (java | test) / resources Here I see one bad thing. All configuration files will be in the class directory, and I'm not sure if this is correct.

3. Move only the servlet configuration to / main / (java | test) / resources and save the other Spring configuration files in the / WEB -INF / directory.

So what do you recommend? What are the best methods for hosting configuration files when using Spring with Maven and JUnit?

UPDATE: fixed directory name in parameters 2. and 3.

UPDATE: I found a very interesting read [1] about best practices in Spring. He looks very promising and confirms Ralphโ€™s decision. I'm still not happy with the META-INF directory in WEB-INF/classes , but, well ... nothing is perfect.

[1] http://gordondickens.com/wordpress/2012/07/03/enterprise-spring-best-practices-part-1-project-config/

+4
source share
1 answer

A common template (for example, used by Spring Roo applications) is to place configuration files under src\main\resources\META-INF\spring\

Then you can load them through the same classpath:META-INF\spring\application-context.xml expression classpath:META-INF\spring\application-context.xml in the tests as well as in your application.

+11
source

All Articles