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

SpringCloud 项目启动出现未能配置数据源

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.查询自己的项目是否需要连接数据源 若不需要

启动了添加注解

@SpringBootApplication(,exclude = { DataSourceAutoConfiguration.class })

排除数据源的自动配置类。

2.、项目使用了Druid, 这时而又非原生的配置,比如增加了动态数据源支持。

这时需要在启动类上增加:

@SpringBootApplication(exclude ={DruidDataSourceAutoConfigure.class} )

排除掉Druid的数据源的自动配置类。

3.在 pom.xml 配置文件中查看是否配置了数据连接技术 spring-boot-starter-jdbc 包 ,在启动配置文件时 ,Spring Boot 的自动装配机制就会去配置文件中找,相关的数据库的连接配置信息,如果找不到则抛出异常信息

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>

不需要就先注释掉

4.本地启动或者开发环境启动 可以选择先添加上 数据源的文件配置

  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/test?useSSL=false&serverTimezone=CTT
    username: root
    password: root
    hikari:

原因:项目启动时引用了数据源配置的starter,但是配置文件又未按照starter里的配置方式配置,这时就会出现未能找到连接数据源。解决方式就是要么按照原生配置方式来配置,要么排除掉这个自动配置类。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值