原因: 无法确定合适的驱动程序类 : Spring Boot 使用 Eclipse

huangapple go评论79阅读模式
英文:

Reason: Failed to determine a suitable driver class : spring boot using eclipse

问题

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

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: 无法确定合适的驱动程序类
2020-10-09 19:17:13.032  INFO 2692 --- [           main] o.apache.catalina.core.StandardService   : 正在停止服务 [Tomcat]
2020-10-09 19:17:13.065  INFO 2692 --- [           main] ConditionEvaluationReportLoggingListener : 

启动应用程序时出错。要显示条件报告,请使用 'debug' 模式重新运行应用程序。
2020-10-09 19:17:13.073 ERROR 2692 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
应用程序启动失败
***************************

描述:

无法配置数据源:未指定 'url' 属性,且无法配置嵌入式数据源。

原因:无法确定合适的驱动程序类


操作:

考虑以下内容:
    如果您想要使用嵌入式数据库(H2、HSQL 或 Derby),请将其放置在类路径中。
    如果您有要从特定配置文件加载的数据库设置,可能需要激活它(当前未激活任何配置文件)。

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>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
英文:

I am getting following error in console :

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
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

答案1

得分: 4

以下是要翻译的内容:

你能否请尝试在你的 application.properties 文件中使用以下属性。

spring.datasource.driver-class-name=org.postgresql.Driver
英文:

Could you please try the below property in you application.properties file.

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

huangapple
  • 本文由 发表于 2020年10月9日 22:20:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64281883.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定