2013-07-28 31 views
2

我是Spring的新手,并试图理解web.xml文件。 我创建使用STS一个新的Spring MVC的Maven项目,春季的application-config.xml vs mvc-config.xml

我的应用程序-config.xml中VS MVC-config.xml文件之间有点困惑...

MVC-config.xml中包含的servlet映射但什么样的信息呢的应用配置文件包含..

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

回答

2

一般的MVC配置(/WEB-INF/mvc-config.xml)包含由控制器层所需的豆(例如控制器,视图解析器......)应用程序配置(classpath:spring/application-config.xml)用于模型层(这里是哟你可以定义daos,服务......)

+0

是否有可能在其他类中的mvc-config.xml中定义的引用/自动装配到/定义的bean?我试图注入,在@Component类mvc-config.xm中定义的RequestMappingHandlerAdapter,它不工作,有什么想法? – pinkpanther

+0

@pinkpanther只是问另一个问题,并提供一些更多的细节。 –