spring-mvc.xml 和 application-context.xml的區別

application-context.xml是全局的,應用於多個serverlet,配合listener一塊兒使用,web.xml中配置以下:
<!-- 配置監聽器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

spring-mvc.xml 是spring mvc的配置,web.xml中配置以下:
<!--配置springmvc DispatcherServlet-->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
application-context.xml這個通常是採用非spring mvc架構,用來加載Application Context。若是直接採用SpringMVC,只須要把全部相關配置放到spring-mvc.xml中就好,通常spring mvc項目用不到多個serverlet
相關文章
相關標籤/搜索