问题
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>