启动报错Failed to configure a DataSource: ‘url‘ attribute is not specified

报错信息:

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


Process finished with exit code 1

错误原因:
Springboot启动时候,需要找到数据库配置,而配置信息没被加载或者配置信息错误

解决方法:

一,模块不需要数据库操作,且没有配置数据库:

1.添加上数据库配置,在application.properties(.yml)文件
2.在启动类上添加属性,默认不去加载数据库配置(如下)

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

二,模块需要数据库操作,需要配置数据库

确认spring.datasource是否配置正常:

1.检查(创建)application.properties或application.yml

2.检查(.properties)(.yml)语法

3.检查application.properties或application.yml位置

确认Mybatis xml里包名和mapper接口包名是否一致

https://www.cnblogs.com/west-iversion/p/12168069.html

确认是不是application.yml配置文件文件没有被扫描

https://www.cnblogs.com/XingXiaoMeng/p/14738060.html
https://blog.csdn.net/weixin_43158695/article/details/104717561

application.yml配置格式

https://www.cnblogs.com/fanrenren/p/11352642.html

application.yml实例

spring:
  thymeleaf:
    prefix: classpath:/static/
    suffix: .html
  datasource:
      url: jdbc:mysql://localhost:3306/mmall?useUnicode=true&characterEncoding=UTF-8
      username: root
      password: mysql
      driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

application.properties实例

server.port=8080

server.tomcat.uri-encoding=utf-8

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mmall
spring.datasource.username=root
spring.datasource.password=mysql
spring.thymeleaf.prefix=classpath:/static/

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值