1、如果web.xml不配置contextConfigLocation时,工程会默认加载WEB-INF下的 mvc-dispatcher-servlet.xml文件,如果该目录下没有,启动tomcat时就会报:

Exception

javax.servlet.ServletException: Servlet.init() for servlet [mvc-dispatcher] threw exception
	
Root Cause
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
正确的默认配置:

spring mvc web工程里contextConfigLocation 和 classpath

 

2、如果想指定自己的xml或多个xml时,这个时候就用到了contextConfigLocation.同时要注意引用顺序。

spring mvc web工程里contextConfigLocation 和 classpath

相关文章:

  • 2021-11-20
  • 2021-09-28
  • 2022-02-10
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2021-07-07
  • 2021-11-28
  • 2021-11-18
  • 2021-11-18
  • 2022-12-23
  • 2021-09-10
相关资源
相似解决方案