【问题标题】:Reason: Failed to determine a suitable driver class : spring boot using eclipse原因:无法确定合适的驱动程序类:spring boot using eclipse
【发布时间】:2021-01-24 15:26:51
【问题描述】:

我在控制台中收到以下错误:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-10-09 19:17:13.032  INFO 2692 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-10-09 19:17:13.065  INFO 2692 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-09 19:17:13.073 ERROR 2692 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

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.2.10.RELEASE</version>
        <relativePath />
        <!-- lookup parent from repository -->
    </parent>
    <groupId>com.merchant</groupId>
    <artifactId>merchantconfiguration</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>merchantconfiguration</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-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </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>

application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/hitachipyg_db 
spring.datasource.username=postgres
spring.datasource.password=hitachi@123
spring.jpa.show.sql=true
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto= update spring.datasource.driver-class-name=org.postgresql.Driver

【问题讨论】:

  • 当 spring-boot 找不到 spring.datasource.url 属性时会发生此异常。你是如何运行代码的?您的代码是否可以从 application.properties 读取其他属性?

标签: java spring spring-boot hibernate maven


【解决方案1】:

请您试试application.properties 文件中的以下属性。

spring.datasource.driver-class-name=org.postgresql.Driver

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 2021-09-12
    • 2019-12-06
    • 2020-10-23
    • 2023-02-04
    • 2020-01-14
    • 2019-03-18
    • 2019-01-09
    • 2019-05-27
    相关资源
    最近更新 更多