Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

Spring Boot启动时抛出“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured”错误信息。

今天创建了一个Spring Boot当简单程序,该Spring Boot不连接数据库,因此就没有配置数据库信息。启动Spring Boot时抛出如下错误信息:

***************************

APPLICATION FAILED TO START

***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:

If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.

If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Process finished with exit code 1

上面错误信息大概意思为“没有配置utl属性,不能创建嵌入式数据源”。启动Spring Boot当代码如下:

@SpringBootApplication()
public class HealthFireFightingApplication {
   public static void main(String[] args) {
       SpringApplication.run(HealthFireFightingApplication.class, args);
   }
}

Spring Boot默认会自动为我们配置很多信息,我们既然没有数据库信息,可以使用 exclude 排除指定当配置信息。如下:

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class HealthFireFightingApplication {
   public static void main(String[] args) {
       SpringApplication.run(HealthFireFightingApplication.class, args);
   }
}

上面 @SpringBootApplication 注解将排除 DataSourceAutoConfiguration 配置。再次启动 Spring Boot 就不会报错了。

一个不注意小事情的人,永远不会成功大事业。——戴尔·卡耐基
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号