0
votes

Échec de la liaison des propriétés sous "à com.zaxxer.hikari.HikariDataSource:" Springboot

J'ai déjà ajouté ojdbc ddriver et inclus la dépendance dans pom, mais j'obtiens toujours l'erreur mentionnée dans le titre. Veuillez aider.

Auparavant, j'ai exécuté l'application avec une base de données postgres locale. Maintenant, essayez de vous connecter à une base de données oracle distante et rencontré ce problème. Je suis connecté aux pare-feu nécessaires. L'application a démarré et s'est exécutée comme prévu avec le postgresdb.

J'obtiens les journaux suivants en essayant de démarrer mon application maintenant -

##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

Le fichier pom est comme ci-dessous

<?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 -

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


6 commentaires

Pouvez-vous publier votre fichier application.properties ?


Application.properties ajoutée


Vérifiez ma réponse. Et donnez une réponse après vérification.


Vous avez écrit un commentaire sur pom.xml (j'ai supprimé ce contenu , mais cela ne devrait pas avoir d'importance, si nécessaire, veuillez le demander dans les commentaires) . Lequel avez-vous commenté?


<groupId> package </groupId> <artifactId> QualityScore </artifactId> <version> 0.0.1-SNAPSHOT </version> <name> QualityScore </name> <description> Projet de démonstration dans Spring Boot </description>


@AvjitBarua, j'ai ajouté la section commentée, et comme je l'ai dit, le même vieux problème persiste et un nouveau est survenu, j'obtiens une erreur dans pom.xml - "Impossible de lire le descripteur d'artefact pour com.oracle:ojdbc8:jar :inconnue"


3 Réponses :


0
votes

votre application.properties est erronée. Tu as:

#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=*****

mais vous n'avez pas défini votre nom de classe de pilote. devrait être:

#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=*****

Cordialement!


1 commentaires

Salut, j'ai ajouté la propriété (... OracleDriver) comme vous l'avez mentionné, mais j'obtiens toujours la même erreur.



0
votes

J'ai la solution ou le correctif. J'ai ajouté la propriété suivante dans application.properties

spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver

et a explicitement spécifié le pilote (ojdbc8) dans les modules de la structure du projet. Maintenant ça marche!!! Merci à tous pour votre aide!!


0 commentaires

0
votes

Dans mes classes de test de contrôleur, cette erreur s'est produite lors de l'exécution des tests. Même avec l'ensemble de propriétés spring.datasource.driver-class-name .

Pour résoudre ce problème, nous avons ajouté l'attribut DataSouce avec l'annotation @MockBean dans les classes de test du contrôleur:

 @MockBean
 private DataSource dataSource;

Les classes de test ont parfaitement fonctionné.


0 commentaires