项目场景:
Spring Boot项目启动报错
问题描述
后端启动报错:
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-01-02T16:09:40.511+08:00 ERROR 18536 --- [together-now-backend] [ restartedMain] o.s.boot.SpringApplication : Application run failed
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:410) ~[spring-beans-6.1.2.jar:6.1.2]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:391) ~[spring-beans-6.1.2.jar:6.1.2]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-6.1.2.jar:6.1.2]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:778) ~[spring-boot-3.2.1.jar:3.2.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:341) ~[spring-boot-3.2.1.jar:3.2.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1358) ~[spring-boot-3.2.1.jar:3.2.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1347) ~[spring-boot-3.2.1.jar:3.2.1]
at com.wen.togethernow.TogetherNowBackendApplication.main(TogetherNowBackendApplication.java:15) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.2.1.jar:3.2.1]
原因分析:
可能是版本冲突了
我的项目使用的技术栈及版本:
1、Java:17
2、spring boot:3.2.1
3、mybatis:3.0.3
4、mybatis plus:3.5.2
还有其他的和这个报错没关系我就不写了
当时没有导入mybatis plus
之前我的项目可以正常运行,但是导入mybatis plus
之后项目开始报错,而且还出现了ddlApplicationRunner
字样,我想到有可能是mybatis plus
有问题,最有可能的就是版本冲突了。
解决方案:
导入最新版的mybatis plus包
在maven仓库找了最新版的mybatis plus
3.5.5导入:
<!-- 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>
问题解决!