SpringBoot项目启动失败: java.io.FileNotFoundException: class path resource [config/mybatis/mapper3/] cannot be resolved to URL because it does not exist

之前配置的多个数据源都没有问题,如上图,3是新加的,还没有文件

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

修改后:

问题到了这一步,你难得不好奇为啥一模一样的配置,有*跟没*有啥区别,为啥会有这种错误?

又到了翻源码的环节。

如果配置的是

classpath:config/mybatis/mapper3/*.xml

java.io.FileNotFoundException:class path resource [config/mybatis/mapper3/] cannot be resolved to URL because it does not exist

但如果配置的是classpath*:config/mybatis/mapper3/*.xml , 这个方法就不报错了么,我们来一探究竟

直接跳过了for循环,关键在下面这个方法,CLASSPATH_ALL_URL_PREFIX = CLASSPATH_ALL_URL_PREFIX

加*的走到了这个方法

// all class path resources with the given name
 return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));

返回的Resource[] rootDirResources   = new Resource[0] ;

不加*的走了下面这个

 // a single resource with the given name 
 return new Resource[] {getResourceLoader().getResource(locationPattern)};

classpath:config/mybatis/mapper3/

new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());

返回的 Resource[] rootDirResources 有一条数据 [class path resource [config/mybatis/mapper3/]]

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐