无法配置数据源:'url'

Failed to configure a DataSource: 'url'

我启动了新的 Spring 引导应用程序,但是当我尝试 运行 它时遇到了以下问题:

localhost 8080 already in use

在那之前我有一个旧的 eeproject,我决定删除它并尝试删除那里的 tomcat 属性。在我尝试重新 运行 我的 Spring 项目后,当我开始 运行 它时:

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.

我该怎么办?

我的主Class:

package com.example.sweater;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->

</parent>
<groupId>com.example</groupId>
<artifactId>serving-web-content</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>serving-web-content</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mustache</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>
</dependencies>

<build>
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
</plugins>
</build>

</project>
  1. 打开您的终端并 运行 sudo lsof -i tcp:8080 获取 PID,然后使用 kill -9 xxxxx 终止进程,其中“xxxxx”是您的 PID,现在您可以在端口重新启动您的应用程序8080。 对于 windows,键入 netstat -aon | find "8080" 并使用 taskkill /F /PID xxxxx 终止进程,其中“xxxxx”是您的 PID。
  2. 如果你还没有添加SQL依赖,先添加SQL依赖(例如MySQL或PostgreSQL)然后在你的资源->application.properties 添加您的 SQL 属性。 如果您不打算使用数据库,请删除 Spring JPA 依赖项。

从 pom 文件中删除以下依赖项。

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Spring-如果在类路径上发现 spring-boot-starter-data-jpa 依赖项,启动会自动尝试查找数据源。