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

#端口
server:
  port: 8081
#swagger
zyj:
  #启动(true)/关闭(false)
  swagger-open: true
spring:
  redis:
    #连接地址
    host: ip
    #连接密码
    password: 123456
    #端口
    port: 6379
    #Redis默认情况下有16个库,这里配置具体使用的库,默认是0
    database: 4
  #配置MySQL
  datasource:
    name: master
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    dynamic:
      primary: master #设置默认的数据源或者数据源组,默认值即为master
      strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源.
      druid:
        #配置初始化大小/最小/最大
        initial-size: 5
        min-idle: 5
        max-active: 20
        #获取连接等待超时时间
        max-wait: 60000
        #间隔多久进行一次检测,检测需要关闭的空闲连接
        time-between-eviction-runs-millis: 60000
        #一个连接在池中最小生存的时间
        min-evictable-idle-time-millis: 300000
        #打开PSCache,并指定每个连接上PSCache的大小.oracle设为true,mysql设为false.分库分表较多推荐设置为false
        pool-prepared-statements: false
        max-pool-prepared-statement-per-connection-size: 20
        #配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
        filters: stat, wall
        #通过connectProperties属性来打开mergeSql功能;慢SQL记录
        connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
      datasource:
        #数据编码格式:characterEncoding=utf8
        #数据库提前八小时配置:serverTimezone=GMT%2B8
        #返回受影响条数:useAffectedRows=true
        master:
          url: jdbc:mysql://ip:3306/zyj_model?characterEncoding=utf8&serverTimezone=GMT%2B8&useAffectedRows=true
          username: root
          password: 123456
        zyj:
          url: jdbc:mysql://ip:3306/zyj_group?characterEncoding=utf8&serverTimezone=GMT%2B8&useAffectedRows=true
          username: root
          password: 123456

不在主函数上加排除的话还有其他 的解决办法码
报错是这样
Description:

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

Reason: Failed to determine suitable jdbc url
求学求学添加的依赖有三个

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.22</version>
        </dependency>
<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>
<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.6</version>
        </dependency>

也许你写错位置了driver-class-name: com.mysql.cj.jdbc.Driver你应该写到下面,如下

        master:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://ip:3306/zyj_model?characterEncoding=utf8&serverTimezone=GMT%2B8&useAffectedRows=true
          username: root
          password: 123456
        zyj:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://ip:3306/zyj_group?characterEncoding=utf8&serverTimezone=GMT%2B8&useAffectedRows=true
          username: root
          password: 123456

不想排除spring自带的数据源配置类,那就在driver-class-name配置下面加上url username password配置喽。

url: jdbc:mysql://ip:3306/zyj_model?characterEncoding=utf8&serverTimezone=GMT%2B8&useAffectedRows=true
username: root
password: 123456
把这三行放到和你的driver-class-name同级试试

少了多数据源依赖

 <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
        </dependency> 

参考这个配置 试试

img

https://github.com/zhikecore/superblog/blob/main/blog-base/pom.xml

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632