Spring Framework:配置数据源失败:未指定“url”属性,无法配置嵌入式数据源

问题描述 投票:0回答:1

目前,我正在尝试运行我之前制作的 Spring Boot 项目。当我制作这个项目时,我的 JDK 版本是 17,但现在这个 JDK 版本是 11,因为 AEM(ADOBE EXPERIENCE MANAGER)在 JDK 11 或更低版本上运行。目前,当我尝试运行这个项目时,它会产生一个错误。

下面是完整的堆栈跟踪

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2m2023-02-21 12:49:14.134[0;39m [31mERROR[0;39m [35m10964[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.d.LoggingFailureAnalysisReporter  [0;39m [2m:[0;39m 

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

我试过

mvn clean
mvn install
但我仍然面临同样的问题。

下面是我的

pom.xml

<?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 https://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.7.3</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>practice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>practice</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
java spring-boot spring-data-jpa pom.xml java-11
1个回答
0
投票

我不认为这是 JDK 的问题,而是您没有指定要使用的数据库的 url 路径。如果您使用的是 MySQL 数据库,请打开 src/main/resources/application.properties 并更改此行:

spring.datasource.driverClassName=com.mysql.jdbc.Driver

到这条线

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

如果上述步骤不能解决错误,请在此处阅读更多信息。

无法配置数据源:未指定“url”属性,无法配置嵌入式数据源

© www.soinside.com 2019 - 2024. All rights reserved.