重写项目Mybatis转为Mybatis-Plus时,Mybatis使用xml实现的sql语句到Mybatis-Plus中不能使用的问题

问题

Mybatis-Plus中明明配置的代码是没有问题的,如下:

mybatis-plus.mapper-locations=classpath*:com/eds/education_system/service_auto_schedule/mapper/xml/*.xml

但是却出现了以下报错:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'classController': Unsatisfied dependency expressed through field 'classService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'classServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'classMapper' defined in file [C:\Users\23769\IdeaProjects\education_system\service\service_auto_schedule\target\classes\com\eds\education_system\service_auto_schedule\mapper\ClassMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\23769\IdeaProjects\education_system\service\service_auto_schedule\target\classes\com\eds\education_system\service_auto_schedule\mapper\xml\SubjectMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [C:\Users\23769\IdeaProjects\education_system\service\service_auto_schedule\target\classes\com\eds\education_system\service_auto_schedule\mapper\xml\SubjectMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Subjects'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Subjects

分析

截取其中的一段分析:

 Cause: java.lang.ClassNotFoundException: Cannot find class: Subjects

这是由于找不到我的Subjects实体类,因此我去看了xml文件然后发现

<select id="queryInfo" resultType="Subjects">
**** 你的sql语句 ****
</select>

这时还没感觉什么不对,但是我看了看我之前使用Mybatis写的项目中是有事先申明我的实体类的位置的,而Mybatis-Plus是没有的,因此解决方法其实就显而易见了。 

解决方法

指明你的实体类的位置

<select id="queryInfo" resultType="com.eds.education_system.pojo.Subjects">
**** 你的sql语句 ****
</select>

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值