写在前面:springboot整合Mybatis-plus时,引入的Mybatis-plus版本不能太高,否则会出现一系列奇怪的问题。
总结来说:
问题:如果你的项目报错出现如下字样
- Caused by: org.springframework.beans.factory.BeanCreationException:
- Caused by: java.io.IOException: Failed to parse mapping resource:
- Caused by: org.apache.ibatis.builder.BuilderException
- Caused by: org.apache.ibatis.type.TypeException:
- org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'ddlApplicationRunner' is expected to be of type 'org.springframework.boot.Runner' but was actually of type 'org.springframework.beans.factory.support.NullBean'
- java.lang.IllegalArgumentException: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
解决方案:也就是出现(ibatis,bean,factory……)等问题,然后你用常规方法debug都失败,那么你可以试试降低引入的mp版本,例如我将将3.5.2降至3.4.2,问题完美解决
以上6个报错,是我在我手中4个不同的springboot项目引入高版本Mybatis-plus后出现的不同问题,不得不感叹:同样一个高版本Mybatis-plus原因,在不同项目中体现的报错也是千奇百怪啊!
原因:精确的原因,我并没有查到准确资料,因为版本兼容性导致的问题本身就多种多样,不能一概而论,但是可以这么理解:Mybatis plus是通过反射,动态代理等技术实现的,包括对一系列bean,bean factory的操作,所以当遇到(ibatis,bean,factory……)的问题,不妨试试降低mp版本!
由于暑期软件开发实习需要,今晚回顾了springboot的一些基本操作,因为是回顾基础知识,所以我选择从零开始构建springboot,但是过程中遇到了一系列很奇怪的问题,GPT和网上都没有恰当的解决方案。
在一步步debug之后,发现去掉Mybatis-plus依赖程序就正常运行,忽然想到应该是因为Mybatis-plus引入的版本太高导致了如下一系列问题呢,随即将3.5.2降至3.4.2,发现问题完美解决,如下报错:
- java.lang.IllegalArgumentException: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
- org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'ddlApplicationRunner' is expected to be of type 'org.springframework.boot.Runner' but was actually of type 'org.springframework.beans.factory.support.NullBean'
- Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'. Cause: java.lang.ClassNotFoundException: Cannot find class: Category
- Caused by: org.apache.ibatis.builder.BuilderException
- Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file
- Caused by: java.io.IOException: Failed to parse mapping resource: 'file [D:\Study\java-project\sky-take-out\sky-server\target\classes\mapper\CategoryMapper.xml]'
- Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource
本人211软件工程大二在读,平时喜欢做做项目,打打比赛。以后也会出一些深度学习,计算机视觉相关的学习分享,如果你喜欢的话,可以点赞或者关注一下,我们共同进步!