I've looked at a bunch of sample project and I can't seem to tease out a common best practice. I've seen Spring bean files sometimes go in the web-app/WEB-INF
directory. I've seen this in conjunction with with a servlet definition in web.xml
like this:
<servlet>
<servlet-name>my-stuff</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/my-stuff-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
But I've also seen bean config files included within web.xml
top level -- i.e. outside of a servlet. What does this mean? Is this for cross-servlet beans? Sometimes it's in the web-app/WEB-INF
directory and sometimes its in src/main/resources
. Also I've seen other bean files defined in WAR modules with just about everything in src/main/resources
.
I've read and re-read the Spring documentation, but the only convention I found is that by default a servlets context config file should be in the web-app/WEB-INF
directory named {servlet-name}-servlet.xml
.
So what's the best practice and why?