当前位置:   article > 正文

Springboot3整合myBatisplus报错:Bean named ‘ddlApplicationRunner‘ is expected to be of type ‘org.sprin_bean named 'ddlapplicationrunner' is expected to b

bean named 'ddlapplicationrunner' is expected to be of type 'org.springframe

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'

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

demo框架如下:

(1)Demo1Application.java

(2)controller层:JOJOController.java

(3)service层:JOJOService.java

(4)mapper层:JOJOMapper.java

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

(6)pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>3.1.7</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>demo1</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>demo1</name>
  15. <description>demo1</description>
  16. <properties>
  17. <java.version>17</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-web</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>com.mysql</groupId>
  26. <artifactId>mysql-connector-j</artifactId>
  27. <scope>runtime</scope>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.projectlombok</groupId>
  31. <artifactId>lombok</artifactId>
  32. <optional>true</optional>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-test</artifactId>
  37. <scope>test</scope>
  38. </dependency>
  39. <dependency>
  40. <groupId>com.baomidou</groupId>
  41. <artifactId>mybatis-plus-boot-starter</artifactId>
  42. <version>3.5.3</version>
  43. </dependency>
  44. </dependencies>
  45. <build>
  46. <plugins>
  47. <plugin>
  48. <groupId>org.springframework.boot</groupId>
  49. <artifactId>spring-boot-maven-plugin</artifactId>
  50. <configuration>
  51. <image>
  52. <builder>paketobuildpacks/builder-jammy-base:latest</builder>
  53. </image>
  54. <excludes>
  55. <exclude>
  56. <groupId>org.projectlombok</groupId>
  57. <artifactId>lombok</artifactId>
  58. </exclude>
  59. </excludes>
  60. </configuration>
  61. </plugin>
  62. </plugins>
  63. </build>
  64. </project>

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

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

2、解决办法:

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

  1. <dependency>
  2. <groupId>com.baomidou</groupId>
  3. <artifactId>mybatis-plus-boot-starter</artifactId>
  4. <version>3.5.3</version>
  5. </dependency>

改为

  1. <dependency>
  2. <groupId>com.baomidou</groupId>
  3. <artifactId>mybatis-plus-boot-starter</artifactId>
  4. <version>3.5.5</version>
  5. </dependency>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/244372?site
推荐阅读
相关标签
  

闽ICP备14008679号