关于spring:Spring-boot-启动提示数据源错误

9次阅读

共计 1695 个字符,预计需要花费 5 分钟才能阅读完成。

在启动 Spring Boot 的我的项目的时候提醒数据源未配置的谬误。

09:52:08.333 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:233)
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:174) 

Spring 会提醒你残缺的导致启动谬误的信息是:

***************************
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 

谬误剖析

从下面的启动信息来看,曾经说得十分分明了,就是因为你配置了 Spring 的数据组件,然而你没有配置相应的数据源。

因为这个会导致你的启动失败。

解决办法

有上面的集中解决办法:

退出 H2 包

最简略的解决办法就是在依赖中增加 H2 的数据库,如果你应用 Spring Batch 的话,这个组件也是须要的,因为 Spring 会应用 H2 为数据源。

增加数据源配置

如果你曾经增加了数据库驱动,例如你增加了 mysql 的数据库驱动。

那么你须要制订 Mysql 的数据库连贯参数。

spring.datasource.url=jdbc:mysql://localhost:3306/myDb
spring.datasource.username=user1
spring.datasource.password=pass
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 

在启动时候不载入数据源配置。

你可用在启动的时候不载入数据源配置。

可用在启动类下面,增加上面的注解。

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) 

你也能够在启动配置文件下面,增加上面的内容,这样可能保障你在启动的时候不载入数据源配置类。

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAuto

https://www.ossez.com/t/spring-boot/504

正文完
 0