3
votes

I created a simple spring-web-mvc project based on maven. The sample includes two configuration files. One in src / main / resources / spring / application-config.xml and a second in src / main / webapp / WEB-INF / mvc-config.xml

Is that config normal? I think it is just configuration splitting basics mvc stuff in mvc-config.xml and application-config.xml for spring commons or?

1

1 Answers

5
votes

For a web application then that is fairly normal - although the naming convention for the two files is often dispatcher-servlet.xml and applicationContext.xml.

The dispatcher-servlet.xml (or mvc-config.xml as in your question) is the configuration file for the web application context and contains the web specific beans and configuration for Spring MVC. It is loaded by the DispatcherServlet when the application starts up.

The applicationContext.xml (or application-config.xml as in your question) is the configuration file for the main Spring application context and contains the non-web business beans (typically services, DAOs etc). This file is often spilt into fragments - with a fragment containing the beans for each logical layer within the app. This file is typically loaded by the ContextLoaderListener defined in the web.xml.

Spring automatically sets the main application context as the parent of the web application context. This ensures that web components (such as controllers) have access to business beans in the application context. However, business beans are not able to see beans in the web application context.