相关推荐recommended
Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin
作者:mmseoamin日期:2024-01-25

1、错误:

我用Springboot3.1.7整合myBatisplus3.5.3时,出现下面的错误

Bean named 'ddlApplicationRunner' is expected to be of type 'org.springframework.boot.Runner' but was actually of type 'org.springframework.beans.factory.support.NullBean'

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin,第1张

明明我的代码刚开始写,就起了一个头,竟然报错了!

demo框架如下:

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin,第2张

(1)Demo1Application.java

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin,第3张

(2)controller层:JOJOController.java

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin,第4张

(3)service层:JOJOService.java

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin,第5张

(4)mapper层:JOJOMapper.java

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin,第6张

(5)数据库实体类:jojo.java

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin,第7张

(6)pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        3.1.7
         
    
    com.example
    demo1
    0.0.1-SNAPSHOT
    demo1
    demo1
    
        17
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            com.mysql
            mysql-connector-j
            runtime
        
        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.5.3
        
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        paketobuildpacks/builder-jammy-base:latest
                    
                    
                        
                            org.projectlombok
                            lombok
                        
                    
                
            
        
    

是不是看起来非常正确!!没感觉有什么问题,有很多博客说要加上@MapperScan("com.example.demo1.mapper")之类的,但是我是加上了,还是有错误。

坑就在于springboot3.1.7需要更高版本的myBatisPlus!

2、解决办法:

把myBatisplus的版本升级到3.5.5,就可以了!!!

        
            com.baomidou
            mybatis-plus-boot-starter
            3.5.3
        

改为

        
            com.baomidou
            mybatis-plus-boot-starter
            3.5.5