解决: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
一·问题描述:
(1)启动一个springboot程序,出现如下图异常:
二·异常原因:
Reason: Failed to determine a suitable driver class
原因:不能确定一个合适的数据库驱动程序类
三·解决办法:两种任选一种
方式一:在boot项目的主程序@SpringBootApplication注解中,排除数据源自动配置类
#在主程序中添加如下代码:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
如图所示:
方式二:在应用的 /src/main/resources/application.yml 中添加连接数据库的基本配置信息
spring:
#配置数据源
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.120.131:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=TRUE&serverTimezone=Asia/Shanghai
username: root
password: 552200
如图所示: