以springmvc项目为例,将其打包成springmvc.war文件

springMvc的web.xml中的classpath指项目中的哪个路径

进去WEB-INF,发现底下有3个文件

springMvc的web.xml中的classpath指项目中的哪个路径

我们通常说的classpath指的是WEB-INF下的classes文件

springMvc的web.xml中的classpath指项目中的哪个路径

因为config文件和classes文件是同级目录所以报错
报错信息:parsing XML document from class path resource [config/springMVC.xml]; nested exception is java.io.FileNotFoundException: class path resource [config/springMVC.xml] cannot be opened because it does not exist
说是springMVC.xml没找到

springMvc的web.xml中的classpath指项目中的哪个路径

而我的项目中config文件是放在webapp->WEB-INF下的,所以我要将config文件移到src->main文件夹下

springMvc的web.xml中的classpath指项目中的哪个路径
发现在.war文件下config文件就在WEB-INF->classes文件下了

springMvc的web.xml中的classpath指项目中的哪个路径

说明springMVC.xml配置文件可以被找到,也就是说classpath对应的路径其实就是项目中的src文件中。
后面测试:如果你将config文件放在src->main下也是可以被找到的,放在src->main->source也是可以
--------------------- 
原文:https://blog.csdn.net/hello_noob/article/details/78945170 
 

相关文章:

  • 2021-12-18
  • 2021-08-18
  • 2022-01-05
  • 2022-12-23
  • 2021-10-25
  • 2021-05-13
  • 2022-12-23
猜你喜欢
  • 2022-01-19
  • 2021-09-21
  • 2021-07-31
  • 2021-10-10
  • 2021-07-02
相关资源
相似解决方案