class path resource [mapper/] cannot be resolved to URL because it does not exist

https://blog.csdn.net/gao505/article/details/81393472

 

Spring Cloud项目启动失败:class path resource [mapper/] cannot be resolved to URL because it does not exist

如下截图:

这个是无法解析当前的URL,做出如下修改,classpath 后多加一个“ * ”,修复了这个错误。

修改后:

classpath 和 classpath* 区别: 
classpath:只会到你的class路径中查找找文件; 
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找。当项目中有多个classpath路径,并同时加载多个classpath路径下(此种情况多数不会遇到)的文件,*就发挥了作用,如果不加*,则表示仅仅加载第一个classpath路径;

如果要加载的资源, 不在当前ClassLoader的路径里,那么用classpath:前缀是找不到的, 这种情况下就需要使用classpath*:前缀 。

在多个classpath中存在同名资源,都需要加载, 那么用classpath:只会加载第一个,这种情况下也需要用classpath*:前缀 

注意: 
用classpath*:需要遍历所有的classpath,所以加载速度是很慢的,因此,在规划的时候,应该尽可能规划好资源文件所在的路径,尽量避免使用classpath*。

参考:http://perfy315.iteye.com/blog/2009258

经分析,这样会把依赖工程中的classpath下的都加载进来。最后还是使用classpath,IDEA在编译的时候,没把空文件夹mapper复制到target目录下,导致编译过程中找不到这个目录。所以在mapper目录下新建一个txt文件,避免空文件夹。重新运行就可以通过了。

posted @ 2020-11-10 10:37  M号开发者  阅读(2736)  评论(0编辑  收藏  举报