Java教程

单元测试出现:java.lang.IllegalStateException: Failed to load ApplicationContext

本文主要是介绍单元测试出现:java.lang.IllegalStateException: Failed to load ApplicationContext,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

在运行单元测试的时候出现:java.lang.IllegalStateException: Failed to load ApplicationContext
在这里插入图片描述

java.lang.IllegalStateException: Failed to load ApplicationContext

查看错误提示:
在这里插入图片描述

Description:

Failed to configure a DataSource: ‘url’ attribute is not specified and
no embedded datasource could be configured.
翻译就是:无法配置DataSource:未指定’url’属性,也无法配置嵌入数据源。

很明显,就是你在应用中没有配置datasource的一些相关属性,例如:地址值啊,数据库驱动啊,用户名啊,密码啊,

重点来了:也可以不配置,但是你需要声明一下
启动类头部声明就可以了:

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

问题解决!

这篇关于单元测试出现:java.lang.IllegalStateException: Failed to load ApplicationContext的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!