2

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>

1 Answer 1

3

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...)

Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to get the references/autowiring to/the beans defined in mvc-config.xml in other classes? I'm trying to inject, RequestMappingHandlerAdapter which is defined in mvc-config.xm in a @Component class, it's not working, any ideas?
@pinkpanther Just ask another question and provide some more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.