1. 程式人生 > 其它 >Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could

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

技術標籤:springbootspringboot

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

1. 第一種問題,沒有在application.ym裡面設定driver-class-name和url

解決方法:新增以下程式碼就行了

spring:
  datasource:
    username: root
    password: root
    url: jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf-8&useSSL=true
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    show-sql: true

2.第二種問題,就是打包成pom檔案,但是target裡面沒有application.yml檔案()

我添加了以下程式碼,編譯後發現target裡面沒有application.yml檔案

<packaging>pom</packaging>

<resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

解決方法:刪掉上面的程式碼,刪掉之後重新編譯就有了