Marcel
Marcel

Reputation: 101

After upgrading to Spring Boot 3 and Keycloak 20+, the application failed to start due to missing classes related to Apache HttpClient

After upgrading to Spring Boot 3 and Keycloak 20+, the application failed to start due to missing dependencies related to Apache HttpClient.

The error messages indicated that Keycloak Admin Client was trying to use HttpClient 4, while Spring Boot 3 had moved to HttpClient 5, leading to NoClassDefFoundError for SSLConnectionSocketFactory and HttpClient.

This issue caused Keycloak Admin Client initialization to fail

Initial Attempt:

Upgraded to Spring Boot 3 and Keycloak 20+. and expected Keycloak Admin Client to work as before instead, got NoClassDefFoundError for SSLConnectionSocketFactory and HttpClient.

Added Apache HttpClient 5 (Expected Fix for Spring Boot 3)

<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
    <version>5.2.1</version>
</dependency>

Expected it to resolve the issue but Keycloak Admin Client still failed due to missing HttpClient 4 classes.

Added Apache HttpClient 4 for Keycloak

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.14</version>
</dependency>

Expected it to resolve Keycloak errors while keeping Spring Boot 3's HttpClient 5 intact. Result showed Keycloak started working, but there was a conflict between HttpClient 4 & 5.

Upvotes: 0

Views: 31

Answers (1)

Marcel
Marcel

Reputation: 101

To solve this, I excluded HttpClient 4 from HttpClient 5 dependency. See below

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
<exclusions>
    <exclusion>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
    </exclusion>
</exclusions>

Upvotes: 0

Related Questions