在运行单元测试的时候出现: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})

问题解决!

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐