Spring Boot 升级 3.2 报错 Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String

🚀 作者主页: 有来技术

🔥 开源项目: youlai-mall 🍃 vue3-element-admin 🍃 youlai-boot

🌺 仓库主页: Gitee 💫 Github 💫 GitCode

💖 欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请纠正!

目录

  • 问题描述
  • 原因分析
  • 解决方案(新)
  • ~~解决方案(旧)~~
  • 开源项目

问题描述

youlai-boot 升级 Spring Boot 3.2 版本项目启动报错:

java.lang.IllegalArgumentException: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String

报错截图如下:

在这里插入图片描述

原因分析

mybatis-spring 官方 ISSUE: https://github.com/mybatis/spring/issues/855

项目中使用 mybatis-plus-boot-starter 当前最新版本 3.5.4.1 ,其中依赖的 mybatis-spring 版本为 2.1.1

Spring Boot 升级 3.2 报错 Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String

在 mybatis-spring 2.1.1 版本的 ClassPathMapperScanner#processBeanDefinitions 方法里将 BeanClassName 赋值给 String 变量

在这里插入图片描述

并将 beanClassName 赋值给 factoryBeanObjectType

在这里插入图片描述

但是在 Spring Boot 3.2 版本中FactoryBeanRegistrySupport#getTypeForFactoryBeanFromAttributes方法已变更,如果 factoryBeanObjectType 不是 ResolvableType 或 Class 类型会抛出 IllegalArgumentException 异常。

此时因为 factoryBeanObjectType 是 String 类型,不符合条件而抛出异常。

在这里插入图片描述

解决方案(新)

Mybatis-Plus 于 2023年12月24日发布 mybatis-plus v3.5.5 版本,发布日志声明 升级spring-boot3版本mybatis-spring至3.0.3。

Spring Boot 升级 3.2 报错 Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String

所以升级 Mybatis-Plus 版本为 3.5.5 版本即可,需要注意下 Maven 的坐标标识 是mybatis-plus-spring-boot3-starter,这点和SpringBoot 2 的依赖坐标mybatis-plus-boot-starter有所区别。

        
            com.baomidou
            mybatis-plus-spring-boot3-starter
            3.5.5
        

解决方案(旧)

mybatis-spring 官方 ISSUE 说明在 3.0.3 版本修复此问题

在这里插入图片描述

确实 3.0.3 版本已出

在这里插入图片描述

Mybatis-Plus 官方 ISSUE#5808 下面也说明会在 3.5.5 版本升级 mybatis-spring 依赖修复此问题,但截止到目前只有快照版本 3.5.5-SNAPSHOT 。

所以目前好一点的方案就是手动升级 mybatis-spring 版本为 3.0.3

  com.baomidou
  mybatis-plus-boot-starter
  3.5.4.1
  
      
          mybatis-spring
          org.mybatis
      
  


  org.mybatis
  mybatis-spring
  3.0.3

修改后再重新启动ok

在这里插入图片描述

开源项目

  • SpringCloud + Vue3 微服务商城
Github Gitee
后端 youlai-mall 🍃 youlai-mall 🍃
前端 mall-admin🌺 mall-admin 🌺
移动端 mall-app 🍌 mall-app 🍌
  • SpringBoot 3+ Vue3 单体权限管理系统
Github Gitee
后端 youlai-boot 🍃 youlai-boot 🍃
前端 vue3-element-admin 🌺 vue3-element-admin 🌺

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/a4ff91a75f.html