user1050619
user1050619

Reputation: 20856

application-config.xml vs mvc-config.xml in spring

Im a newbie to Spring and trying to understand the web.xml file. I have created a new SPring MVC Maven project using STS,

I'm little bit confused between the application-config.xml vs mvc-config.xml file...

mvc-config.xml contains the servlet mappings but what information does the application-config file contains..

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/application-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<!--
    - Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Upvotes: 2

Views: 6543

Answers (1)

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22506

Usually the mvc configuration(/WEB-INF/mvc-config.xml) contains the the beans that are needed by the controller layer (e.g. the controllers, view resolvers ...) The application configuration(classpath:spring/application-config.xml) is for the model layer (here you can define daos, services...)

Upvotes: 3

Related Questions