Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

SpringBoot项目编译成功,启动报错

提示信息很明显,通过查看依赖关系,可以找到原因

导致这个问题的原因是因为,在 pom.xml 配置文件中,配置了数据连接技术 spring-boot-starter-jdbc 包 ,在启动配置文件时 ,Spring Boot 的自动装配机制就会去配置文件中找,相关的数据库的连接配置信息,如果找不到则抛出异常信息。

解决方法:

1. 在 SpringBoot 应用程序启动时,排除 jdbc 的自动装配机制

通过注解实现,启动类上添加如下

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 

2. 取消项目中spring-boot-starter-jdbc包的引入

适用于临时测试是否能够正常启动,且不需要数据库的情况。

3. 添加数据库配置

示例

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://10.102.34.xx:3222/xxx_vvv?useUnicode=true&characterEncoding=utf-8  
spring.datasource.username=xxxx
spring.datasource.password=xxxx@123
spring.datasource.druid.filters=config,stat
spring.datasource.druid.connectionProperties=config.decrypt=false;config.decrypt.key=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJm+Ptt7DJ0ztn+Pw62ZTa1u1NSi6M+a/zp0LHzd6ybJx+f5CnszeYT0W/2VZVO+JPU+u2DRDxR9dxUGOanfLj0d47ssUgqZZlIxrrEsxMslnyVKkC0GGp8hgbCTAr+qBqdHZoLx2z4iXY5A/5YwdWqpkq3tLg8PVZT0W9IfzgzwIDAQAB
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource  
spring.datasource.initialSize=2  
spring.datasource.minIdle=1  
spring.datasource.maxActive=20  
# u914du7f6eu83b7u53d6u8fdeu63a5u7b49u5f85u8d85u65f6u7684u65f6u95f4  
spring.datasource.maxWait=60000
原文地址:https://www.cnblogs.com/zjfjava/p/10454363.html