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

以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.****.net/hello_noob/article/details/78945170