Bean named‘ddlApplicationRunner‘is expected to be of type ‘org.springframework.boot.Runner‘

1、问题概述?

项目中使用springboot3.1.7整合mybatiplus3.5.3.2版本实现操作数据库的时候,

springboot整合mybatisplus报错如下:

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' at org.springframework.beans.factory.support.AbstractBeanFactory.adaptBeanInstance(AbstractBeanFactory.java:407) ~[spring-beans-6.0.15.jar:6.0.15]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:388) ~[spring-beans-6.0.15.jar:6.0.15]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-6.0.15.jar:6.0.15]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:762) ~[spring-boot-3.1.7.jar:3.1.7]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:331) ~[spring-boot-3.1.7.jar:3.1.7]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1321) ~[spring-boot-3.1.7.jar:3.1.7]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1310) ~[spring-boot-3.1.7.jar:3.1.7] at com.txc.mybatisplusdemo1.Mybatisplusdemo1Application.main(Mybatisplusdemo1Application.java:12) ~[classes/:na]

2、问题分析

经过多次测试最终发现是由于版本迭代造成的问题。

第一次修改使用了sprigboot2.7.16+mybatiplus3.5.3.2整合之后启动成功没有问题,并且能够正常的访问程序。

第二次去了https://mvnrepository.com/中央仓库,搜索了mybatis-plus-boot-starter的包。发现有baomidou有最新版本的包mybatisplus的包,包如下:

<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.5</version>
</dependency>

进过测试返现springboot3.1.7mybatisplus3.5.5版本可以整合,没有人任何问题。新版本的mybatisplus已经修正了问题。

3、最终使用的pom.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.txc</groupId>
    <artifactId>mybatisplusdemo1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mybatisplusdemo1</name>
    <description>mybatisplusdemo1</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.5</version>
        </dependency>


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.49</version>
        </dependency>


        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <builder>paketobuildpacks/builder-jammy-base:latest</builder>
                    </image>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

 

 

 

转载请说明出处内容投诉
CSS教程_站长资源网 » Bean named‘ddlApplicationRunner‘is expected to be of type ‘org.springframework.boot.Runner‘

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买