Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datas

一、异常现象

我在Spring Boot中关联MySQL进行数据库开发时,正常添加了依赖后,数据库的配置文件中也进行了正常的配置,结果出现了异常信息:

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

异常提示信息中可以看到是当前没有配置相关的数据库源

二、异常原因

spring:
  application:
    name: account
  datasource:
    name: orderingsystem
    url: jdbc:mysql://localhost:3306/orderingsystem?useUnicode=true&characterEncoding=UTF-8
    username: root
    password: 1234

这里我是正常地配置了数据库源的配置信息,后面发现是数据库的配置文件我单独的放到了一个config文件夹中和其他模块的yml配置文件统一存放,结果是当前模块识别不到对应的yml配置文件,所以报了数据库源未配置的异常

三、解决办法

  1. 把配置了数据库源的配置放到当前模块的application.yml/applicaiton.properties中;
  2. 在SpringBootApplication注解中进行数据库配置的排除,@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),指定配置文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值