Springboot 项目 无法读取resources下的mapper文件夹的.xml文件
之前学习的时候遇到的一个问题
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/jevin98/demo/config/dao/SessionFactoryConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [classpath*:/mapper/**.xml]'; nested exception is java.io.FileNotFoundException: class path resource [classpath*:/mapper/**.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:860) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
主要关注此行:
Failed to parse mapping resource: 'class path resource [classpath*:/mapper/**.xml]'; nested exception is java.io.FileNotFoundException: class path resource [classpath*:/mapper/**.xml] cannot be opened because it does not exist
类路径资源[classpath*:/mapper/**]。不能打开xml,因为它不存在
没道理啊?我的文件目录

resources下明明就有这个mapper文件夹,和这个xml文件,为什么会找不到呢
解决思路:
首先,确定了文件名和application,properties下的路径名没错
其次,检查一下测试的方法

问题可能主要出现在配置mapper上,所以检查SessionFactoryConfiguration
关于sqlSessionFactory:
https://blog.csdn.net/u013412772/article/details/73648537
关于sqlSeesionFactoryBean: https://blog.csdn.net/u013412772/article/details/73648537

仔细检查路径和类基本上都没错,知道看到这行:
sqlSessionFactoryBean.setMapperLocations(resolver.getResource(packageSearchPath));
sqlSessionFactoryBean调用的方法中setMapperLocations可能是导致读取不到mapper资源的原因
关于PathMatchingResourcePatternResolver : https://www.cnblogs.com/loveLands/articles/9863195.html
果然getResource 和 getResources不同
getResource():
1.从类的根路径下获取文件
getResources():
1.获取所有类路径下的指定文件
可以通过classpath前缀指定,从所有的类路径下获取指定文件,与classpath前缀的区别是classpath前缀只能获取当类路径下的资源文件,而classpath前缀可以获取所有类路径下的资源文件,包括jar包中的。
Springboot 项目 无法读取resources下的mapper文件夹的.xml文件的更多相关文章
- Maven项目读取resources下文件的路径问题(getClassLoader的作用)
读取resources下文件的方法 网上有问答如下:问: new FileInputStream("src/main/resources/all.properties") new ...
- 记录:替换线上springboot项目可执行jar包中依赖jar里的class文件
问题背景: 项目组发现线上版本问题后,定位是由于项目依赖的某个jar包中有个小BUG. 解决方案: 在修改了对应的java文件后,编译出对应的class文件.从生产环境下载项目jar包,解压后,找到对 ...
- Unity 从StreamingAssets文件夹和PersistentData文件夹 保存读取AssetBundle资源
项目中的资源一般我们打包成AssetBundle格式 方便我们加载和热更 而AssetBundle文件 一般保存在StreamingAssets文件夹或则PersistentData文件夹 首先我们看 ...
- php读取excel,以及php打包文件夹为zip文件
1.把文件下载到本地,放在在Apache环境下2.d.xlsx是某游戏的服务器名和玩家列表,本程序只适合此种xlsx文件结构,其他结构请修改index.php源码3.访问zip.php的功能是把生成的 ...
- vue 项目中assets文件夹与static文件夹引用的区别
首先,assets文件夹和static文件夹在vue-cli生成的项目中,都是用来存放静态资源的. 1.assets目录中的文件会被webpack处理解析为模块依赖,只支持相对路径形式.build的时 ...
- HALCON初步:文件夹遍历,文件筛选,文件名拆分,图片读取及保存
[1]文件夹遍历 list_image_files ( : : ImageDirectory, Extensions, Options : ImageFiles) ImageDirectory: 文件 ...
- java基础 File 递归删除文件夹中所有文件文件夹 目录(包含子目录)下的.java文件复制到e:/abc文件夹中, 并统计java文件的个数
File 递归删除文件夹中所有文件文件夹 package com.swift.kuozhan; import java.io.File; import java.util.Scanner; /*键盘录 ...
- C#项目打开/保存文件夹/指定类型文件,获取路径
C#项目打开/保存文件夹/指定类型文件,获取路径 转:http://q1q2q363.xiaoxiang.blog.163.com/blog/static/1106963682011722424325 ...
- cocos项目导入其它源文件时加入依赖库时,头文件提示找不到文件夹中的文件
cocos项目导入其它源文件时加入依赖库时,头文件提示找不到文件夹中的文件解决方法: 选择项目属性->c/c++->常规,在附加包括项目中加上对应的文件夹 cocos test项目的库(所 ...
随机推荐
- Seay源代码审计系统使用
Seay源代码审计系统简介 Seay源代码审计系统使用 如何使用"Seay源代码审计系统"扫描源代码漏洞 Seay源代码审计系统下载安装 github-Seay源代码审计系统
- powershell过杀软工具-xencrypt
在红队攻击中,绕杀软是一个比较常见的技术.对于绕过杀软的方法,有基于黑白名单的,有基于shellloader的,也有基于加密与混淆的.最近在发现了这样一款过杀软的工具,推荐给有缘人,嘻嘻 ...
- centos8 安装lnmp
1. 最小化安装 2. 配置基本信息 hostnamectl set-hostname aaa_name 为了每次系统重新启动时,都可以获取更大的ulimit值,将ulimit 加入到/etc/pro ...
- Vue看板娘教程1.0
Live2D看板娘 前言(PS:本教程使用的Vue项目) 一.下载文件 二.使用步骤 1.引入文件 2.引入js 3.修改app.vue 4.如何换模型? 更换模型的效果 5.如何换语音? 结尾(后续 ...
- Linux没有netstat和ifconfig命令问题
安装了精简版命令行centos7系统,运行netsta查看端口和ifconfig查看IP命令都提示找不到命令. 解决方法: yum search ifconfig 通过yum search 这个命令我 ...
- 虚拟机VM14.X安装Mac10.12启动出现问题的解决方法
虚拟机安装Mac系统,会出现的问题太多,于是乎变记录下来,方便以后使用或者方便大家解决问题. 一:VM14.X安装Mac10.12虚拟机,启动出现下面无限重启问题 解决方法: 亲测有效 在OS X 1 ...
- Windows/Linux 代码共享,开发者称此举使Linux有了更差的结局
英特尔近期披露了 Linux 图形驱动程序相关的一些细节并指出,英特尔的图形驱动程序现在已在 Windows/Linux 之间共享约 60% 的代码库,90~100% 的性能. 针对此事,红帽公司的高 ...
- [教程] Android Native内存泄漏检测方法
转载请注明出处:https://www.cnblogs.com/zzcperf/p/9563389.html Android 检测 C/C++内存泄漏的方法越来越简便了,下面列举一下不同场景下检测C/ ...
- Kafka作为分布式消息系统的系统解析
Kafka概述 Apache Kafka由Scala和Java编写,基于生产者和消费者模型作为开源的分布式发布订阅消息系统.它提供了类似于JMS的特性,但设计上又有很大区别,它不是JMS规范的实现,如 ...
- Mac下打开DDMS(AndroidDeviceMonitor)白屏
mac打开AndroidStudio下的ddms(也就是AndroidDeviceMontor)白屏,是由于jdk版本号较高不兼容导致的,因此需要将jdk降为jdk1.8.0_144就可以来了,但是要 ...