数据源配置异常

先上异常信息
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-31 18:53:44.137 ERROR 15044 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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).
针对如上异常原因有以下几点
  1. 数据源配置不对,需要在application.properties增加如下数据源,注意二选一

    # mysql数据库连接 spring boot 2.0(内置jdbc5驱动)
    #spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    #spring.datasource.url=jdbc:mysql://localhost:3306/testdb?characterEncoding=utf-8&useSSL=false
    #spring.datasource.username=root
    #spring.datasource.password=root
    # mysql数据库连接 spring boot 2.1及以上(内置jdbc8驱动)
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/testdb?serverTimezone=GMT%2B8
    spring.datasource.username=root
    spring.datasource.password=root
    
  2. 在编译后的target目录中配置数据源的application.properties文件位置不对,把资源文件放到classes目录下就好啦

  3. 使用--spring.config.location指定的配置文件的位置
    ① 命令方式
    java -jar xxx.jar --spring.config.location=D:\a\b\application.properties,D:\a\b\logback-spring.xml

    ② idea开发工具参数形式
    在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值