简体   繁体   中英

Quarkus rest client ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl in native mode

I've got a Quarkus project with multiple modules.

└── Parent module
        └── Common module
        └── child module
        └── some module

In the common module I've added the following dependencies (following this guide https://quarkus.io/guides/rest-client ).

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>

The child module has the common module as a dependency.

And the code snippets I'm using inside the child module.

@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApplicationScoped
@RegisterRestClient(configKey = "URL")
@RegisterClientHeaders(AuthorizationHeaderFactory.class)
public interface MyRestClient {

    @POST
    @Path("/{id}")
    FooResponse<FooResponseData> makeFooPayout(@PathParam("id") String accountId,
                                            FooRequest<FooData> requestData);
    }
}

And calling it from another ApplicationScoped class:

    FooResponse<FooResponseData> fooResponse = myRestClient.makeFooPayout(
            payoutDTO.id(),
            fooRequest
    );

When running the the application in native mode it throws the ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl .

I stumbled across this one ( https://quarkus.io/guides/logging#logging-adapters ) thinking it would solve the issue for me.

I followed the guide by trying to exclude the logging from the rest-client dependencies in the parent module.

    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-rest-client</artifactId>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-rest-client-jackson</artifactId>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

And added one of the adapters as suggested in the documentation:

<dependency>
    <groupId>org.jboss.logging</groupId>
    <artifactId>commons-logging-jboss-logging</artifactId>
</dependency>

Why is this not solving the issue? Have I missed something? Am I supposed to exclude the logging dependency inside of the child pom.xml?

This has now been solved, following this guide https://quarkus.io/guides/logging#logging-adapters .

In the common module inside the pom I added this, to ALL dependencies (uncertain if all of them really need to exclude commons-logging ).

   <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>

And also added one of the JBoss Logging adapters as suggested in Quarkus documentation.

<dependency>
    <groupId>org.jboss.logging</groupId>
    <artifactId>commons-logging-jboss-logging</artifactId>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM