今天创建了一个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 就不会报错了。