【Springboot 3.2.1 & mybatis-plus】升级版本遇到的问题

文章讲述了在Springboot3.2.1中使用mybatis-plus时遇到的Invalidvaluetypeforattribute‘factoryBeanObjectType’错误,原因是mybatis-spring版本过低。解决办法是升级mybatis-spring版本并处理Bean类型不匹配的BeanNotOfRequiredTypeException。
摘要由CSDN通过智能技术生成

使用mybatis-plus在Springboot 3.2.1中遇到的问题

Invalid value type for attribute ‘factoryBeanObjectType’: java.lang.String

在这里插入图片描述

造成这个问题的原因是 mybatis-spring依赖版本太低,解决方法就是手动升级mybatis-spring的版本

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
   	<version>3.5.4.1</version>
    <!--排除依赖-->
  	<exclusions>
		<exclusion>
			<artifactId>mybatis-spring</artifactId>
            <groupId>org.mybatis</groupId>
        </exclusion>
    </exclusions>
</dependency>
        <!--升级版本-->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>3.0.3</version>
</dependency>

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’

解决方法:缺什么补什么。

 @Bean
 public DdlApplicationRunner ddlApplicationRunner(@Autowired(required = false) List ddlList) {
        return new DdlApplicationRunner(ddlList);
 }

参考链接:https://github.com/baomidou/mybatis-plus/issues/5867

Spring Boot是一个用于创建独立的、基于Spring的应程序的框架。它简化了Spring应用程序的配置和部署过程,并提供了一套强大的开发工具和约定,使开发人员能够更快地构建高效的应用程序。 MyBatis是一个开源的持久层框架,它可以将SQL语句和数据库操作映射到Java对象中,使得开发人员可以通过简单的配置来实现数据访问层的操作。在Spring Boot中集成MyBatis可以通过添加相应的依赖和配置来实现。 PageHelper是一个用于实现分页功能的MyBatis插件。它可以通过拦截SQL语句并自动添加分页查询的相关信息,从而简化了分页查询的操作。在Spring Boot中集成PageHelper可以通过添加相应的依赖和配置来实现。 Swagger是一个用于生成、描述、调用和可视化RESTful风格的Web服务的工具集。它可以根据代码注解自动生成接口文档,并提供了一个用户友好的界面来测试和调试接口。在Spring Boot中集成Swagger可以通过添加相应的依赖和配置来实现。 下面是集成Spring BootMyBatis、PageHelper和Swagger的步骤: 1. 在pom.xml文件中添加Spring BootMyBatis、PageHelper和Swagger的依赖: ```xml &lt;dependencies&gt; &lt;!-- Spring Boot --&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt; &lt;/dependency&gt; &lt;!-- MyBatis --&gt; &lt;dependency&gt; &lt;groupId&gt;org.mybatis.spring.boot&lt;/groupId&gt; &lt;artifactId&gt;mybatis-spring-boot-starter&lt;/artifactId&gt; &lt;/dependency&gt; &lt;!-- PageHelper --&gt; &lt;dependency&gt; &lt;groupId&gt;com.github.pagehelper&lt;/groupId&gt; &lt;artifactId&gt;pagehelper-spring-boot-starter&lt;/artifactId&gt; &lt;/dependency&gt; &lt;!-- Swagger --&gt; &lt;dependency&gt; &lt;groupId&gt;io.springfox&lt;/groupId&gt; &lt;artifactId&gt;springfox-swagger2&lt;/artifactId&gt; &lt;version&gt;2.9.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;io.springfox&lt;/groupId&gt; &lt;artifactId&gt;springfox-swagger-ui&lt;/artifactId&gt; &lt;version&gt;2.9.2&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; ``` 2. 在application.properties或application.yml文件中配置数据库连接和MyBatis的相关配置: ```properties # 数据库连接配置 spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver # MyBatis配置 mybatis.mapper-locations=classpath:mapper/*.xml mybatis.type-aliases-package=com.example.model # PageHelper配置 pagehelper.helper-dialect=mysql pagehelper.reasonable=true pagehelper.support-methods-arguments=true # Swagger配置 swagger.enabled=true ``` 3. 创建MyBatis的Mapper接口和对应的XML文件,定义数据库操作的SQL语句和映射关系。 4. 创建Spring Boot的Controller类,定义接口的请求路径和处理方法。 5. 在启动类上添加@EnableSwagger2注解,启用Swagger。 ```java @SpringBootApplication @EnableSwagger2 public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 6. 启动应用程序,访问http://localhost:8080/swagger-ui.html可以查看生成的接口文档,并进行接口的测试和调试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值