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

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐