解决 SpringBoot 中 Failed to load ApplicationContext 报错

解决 SpringBoot 中 Failed to load ApplicationContext 报错

1. 原因

原因有很多基本上查看 Caused by 即可知晓.

  1. 导入的包在配置文件内没有设置. (多见于导入数据库, 但是没有在其中进行配置 dataSource; 扫面包没有加.)
  2. 其他类中链接了配置文件. (多见于其他类使用 @PropertySource 注解, 或 @PropertySource 没有加上 classpath:)
  3. 包的冲突

2. 基本解决方法

在测试类中加上:
Application.class 为启动类的名称.

@PropertySource(value = "classpath:application.properties")
@SpringBootTest(classes = {
    
    Application.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)

猜你喜欢

转载自blog.csdn.net/YKenan/article/details/111320433