关于org.mybatis.spring.mapper.MapperScannerConfigurer cannot be cast to

在学习框架Spring和MyBeat时候,参照老师的代码进行#1:1仿照。
虽然进行多次仿照之后,不断改正后最后出现一个java.lang.ClassCastException: org.mybatis.spring.mapper.MapperScannerConfigurer cannot be cast to com.brills.dao.UserDao
在这里插入图片描述
通过百度之后我确认这个问题,我这个菜鸟解决不了

在使用 DevTools 时,通用Mapper经常会出现 class x.x.A cannot be cast to x.x.A。
同一个类如果使用了不同的类加载器,就会产生这样的错误,所以解决方案就是让通用Mapper和实体类使用相同的类加载器即可。
DevTools 默认会对 IDE 中引入的所有项目使用 restart 类加载器,对于引入的 jar 包使用 base 类加载器,因此只要保证通用Mapper的jar包使用 restart 类加载器即可。
在 src/main/resources 中创建 META-INF 目录,在此目录下添加 spring-devtools.properties 配置,内容如下:
restart.include.mapper=/mapper-[\w-\.]+jar
restart.include.pagehelper=/pagehelper-[\w-\.]+jar
使用这个配置后,就会使用 restart 类加载加载 include 进去的 jar 包。
按照网址https://www.cnblogs.com/softidea/p/6065481.html
解决问题
在我的myspring.xml文件中

![在这里插入图片描述ttps://img-blog.csdnimg.cn/20181127153619480.png)
这个路径下创建文件夹和文件如下
在这里插入图片描述
在文件里面写入该配置
在这里插入图片描述

restart.include.mapper=/mapper-[\\w-\\.]+jar
restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar

然后运行就通过了

在这里插入图片描述
很多东西我暂时不能结觉,就只能先这样留下印记,等以后学到过后再了解为什么。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章