一、异常现象
我在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配置文件,所以报了数据库源未配置的异常
三、解决办法
- 把配置了数据库源的配置放到当前模块的application.yml/applicaiton.properties中;
- 在SpringBootApplication注解中进行数据库配置的排除,@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),指定配置文件