springboot Failed to configure a DataSource: 'url' attribute is not specified and no embedded datas

 

  • 问题,项目启动报错:
复制代码
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).
 
说明:
 
未能配置DataSource:未指定“url”特性,也无法配置任何嵌入的数据源。
 
原因:无法确定合适的驱动程序类别
 
操作:
 
考虑以下内容:
 
如果您想要一个嵌入式数据库(H2、HSQL或Derby),请将其放在类路径中。
 
如果您有要从特定配置文件加载的数据库设置,则可能需要激活它(当前没有激活的配置文件)。
复制代码
  • 解决方法:
  • yml或者properties文件没有被扫描到,在pom文件中添加如下,来保证文件都能正常被扫描到并且加载成功 【方法一】
复制代码
<build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
复制代码
  • 检查application.yml文件中数据库配置信息【方法二】
spring:
  datasource:
    url: jdbc:mysql://192.168.1.6:8806/business?useUnicode=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
    username: root
    password: 123456
    driverClassName: com.mysql.cj.jdbc.Driver

 

参考:https://blog.csdn.net/libusi001/article/details/123653595

posted @   低调码农哥!  阅读(151)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-08-19 Ubuntu更改时区
2020-08-19 springboot 添加JWT认证后,Swagger3不能访问
点击右上角即可分享
微信分享提示