小工具知识网

当前位置: 首页 > 行业知识 > SpringBoot:java.lang.IllegalStateException: Failed to load ApplicationContext 错误,已解决

行业知识

SpringBoot:java.lang.IllegalStateException: Failed to load ApplicationContext 错误,已解决

2026-10-28 03:40:43 来源:互联网转载

在使用SpringBoot创建项目的单元测试时,出现java.lang.IllegalStateException: Failed to load ApplicationContext的报错

网上搜索结果

1、检查启动类是否正确配置

2、检查@Mapper注解是否添加

3、启动类头部声明

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

4、检查测试类路径是否与启动类一致

5、尝试使用自动配置注解

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

6、如若上述方法均已尝试,那就基本可以确定是依赖问题,检查一下依赖是否导错了,如果没错,那可能是jdk版本问题。

如果你是jdk9

添加一下依赖尝试解决

            javax.xml.bind            jaxb-api            2.3.0                            com.sun.xml.bind            jaxb-impl            2.3.0                            com.sun.xml.bind            jaxb-core            2.3.0                            javax.activation            activation            1.1.1        

如果你跟我一样是17,那就降到8,就没问题了(我用的方法)

上一篇:linux服务器怎么看cpu?

下一篇:上海祁连仲医疗器械销售中心长春办事处公司地址是在上海是吗,长春只是个办事处