applicationContext.xml和spring-servlet.xml的关系

applicationContext.xml作为spring应用的核心配置文件,由ContextLoaderListener来加载解析。
spring-servlet.xml是SpringMVC应用的主要配置文件,由DispatcherServlet及其父类解析。

applicationContext.xml可以作为应用配置单独使用,但是spring-servlet.xml是applicationContext.xml的子容器,可引用在applicationContext.xml定义初始化的bean。

application-context.xml是全局的,应用于多个serverlet,配合listener一起使用,web.xml中配置如下:


    org.springframework.web.context.ContextLoaderListener


    contextConfigLocation
    classpath*:applicationContext.xml

spring-mvc.xml 是SpringMVC应用的配置,web.xml中配置如下:


  springMVC
  org.springframework.web.servlet.DispatcherServlet
  
    contextConfigLocation
    classpath:config/spring-mvc.xml
  
  1
  true

博客引用:
https://www.cnblogs.com/binlin1987/p/7053016.html

你可能感兴趣的:(SpringMVC)