无法将“下的属性绑定到 com.zaxxer.hikari.HikariDataSource:” Springboot

Failed to bind properties under " to com.zaxxer.hikari.HikariDataSource:" Springboot

我已经添加了ojdbc ddriver并且在pom中包含了依赖,但是还是出现了标题中提到的错误。请帮忙。

早些时候我 运行 使用本地 postgres 数据库的应用程序。现在尝试连接到远程 oracle 数据库,遇到了这个问题。我登录到必要的防火墙。 应用程序启动并按照 postgresdb 的要求执行。

我现在尝试启动我的应用程序时收到以下日志 -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-06 12:08:51.786 ERROR 27236 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

    Property: driverclassname
    Value: oracle.jdbc.OracleDriver
    Origin: "driverClassName" from property source "source"
    Reason: Failed to load driver class oracle.jdbc.OracleDriver in either of HikariConfig class loader or Thread context classloader

Action:

Update your application's configuration


Process finished with exit code 1

pom文件如下

<?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.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
        <groupId>package</groupId>
    <artifactId>QualityScore</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>QualityScore</name>
    <description>Demo project in Spring Boot</description>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>12.2.0.1</version>
        </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 -

##Postgres settings
##spring.datasource.url=jdbc:postgresql:*****
##spring.datasource.username=*****
##spring.datasource.password=*****
##spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true

# Oracle settings
spring.datasource.url=jdbc:oracle:*****
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver

# HikariCP settings
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5

#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

你application.properties错了。你有:

#spring.datasource.url=jdbc:*****
#spring.datasource.username=****
#spring.tasource.password=*****
#spring.jpa.database-platform = *****
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true

spring.datasource.url=jdbc:oracle:****
spring.datasource.username=*****
spring.datasource.password=*****

#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

Recipientlist=*****

但是您没有设置驱动程序-class-名称。应该是:

#spring.datasource.url=jdbc:*****
#spring.datasource.username=****
#spring.tasource.password=*****
#spring.jpa.database-platform = *****
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true

spring.datasource.url=jdbc:oracle:****
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

Recipientlist=*****

此致!

我找到了解决方案或修复程序。 我在 application.properties

中添加了以下 属性
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver

并在项目结构的模块中明确指定了驱动程序(ojdbc8)。 现在可以了!!!谢谢大家的帮助!!

在我的控制器测试 类 中,此错误发生在 运行 测试时。即使设置 spring.datasource.driver-class-name 属性。

为了解决这个问题,我们在控制器测试 类:

中添加了带有 @MockBean 注释的 DataSouce 属性
 @MockBean
 private DataSource dataSource;

测试 类 表现完美。