SpringBoot Keycloak NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplates
Asked Answered
P

2

6

I probably have an issue with my POM in my SpringBoot App.

Currently I am trying to access my Keycloak Server with the "admin-client-keycloak"

But on the call:

Response response = getInstance().realm(REALM).users().create(user);

I get Error:

java.lang.NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplates(Ljava/util/Map;)Ljavax/ws/rs/core/UriBuilder;
        at org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.resolveTemplates(ClientWebTarget.java:178) ~[resteasy-client-3.5.1.Final.jar:3.5.1.Final]
        at org.jboss.resteasy.client.jaxrs.internal.proxy.SubResourceInvoker.invoke(SubResourceInvoker.java:65) ~[resteasy-client-3.5.1.Final.jar:3.5.1.Final]
        at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76) ~[resteasy-client-3.5.1.Final.jar:3.5.1.Final]
        at com.sun.proxy.$Proxy198.realm(Unknown Source) ~[na:na]
        at org.keycloak.admin.client.Keycloak.realm(Keycloak.java:118) ~[keycloak-admin-client-3.4.3.Final.jar:3.4.3.Final]

To be honest: I am not a Maven expert and stitched it together from several web soultions and I expect that some parts are still outdated or something.

the POM dependecys:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.5.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>1.5.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
        <scope>runtime</scope>
    </dependency>

    <!-- Keycloak -->
    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-admin-client</artifactId>
        <version>3.4.3.Final</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-client</artifactId>
        <version>3.5.1.Final</version>
    </dependency>

    <!-- JUnit -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
        <version>2.0.2.RELEASE</version>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.keycloak.bom</groupId>
            <artifactId>keycloak-adapter-bom</artifactId>
            <version>3.4.3.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

The Error occurs from the 'keycloak-admin-client' module.

Now the main question is:

  • Whats the problem? Or is it realy a bug inside the version of 'keycloak-admin-client'?

I guess not which leads my to a second question:

  • How can I found out what I need to change in a situation like this?

Thanks in advance for all suggestions. I primary want to learn how to solve such issues by my own in future.

Kind regards Gregor

EDIT:

Well I am a step further but the issue is still there.

The POM I show you here is a POM of library which is used in other projects. These Project have a 'spring-Boot-starter' which are using the 'jersey' version:1.54.

So the problem seems clear. I added the 'jersey 2.0.2' dependency in the final project POM

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
        <version>2.0.2.RELEASE</version>
    </dependency>

But the issue still exists. How can I force maven use the 2.0.2 version and override the 1.5.?

Only adding the dependecy doesnt seems to help.

Pastorate answered 14/5, 2018 at 16:25 Comment(0)
P
23

Some of the other dependencies are using a different version of the lib jsr311-api. In my case it was the eureka client. I just added an exclude with this dependency in the pom and it worked

     <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        <exclusions>
            <exclusion>
                <groupId>javax.ws.rs</groupId>
                <artifactId>jsr311-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Poppas answered 1/3, 2020 at 2:51 Comment(2)
This was the correct answer for my issue. You saved my day, thank you :)Faucet
I had to follow this #66739248Jemimah
T
3

Please make sure UriBuilder class exist on your project. And make sure only one UriBuilder class (version) exist in your project. (It can be multiple on your project with different versions.) Different versions can be overlapped.

  1. keycloak-admin-client version should same with your keycloak server version.
  2. add additional dependency to pom (versions must be added, for keycloak 3.0.0.Final => resteasy dependecies 3.5.0.Final works for me. Dependencies must be complied.)

        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-admin-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
        </dependency>
    

Note: This is my suggestion, if you are develop multi-layer app. You can divide your project to layers. You can divide your spring boot starter app and keycloak access layer. And use this new project as dependecy.

edit,

see Failed adding user by keycloak-admin-client to Keycloak due to "unknown resource"

i hope these can helps.

Trill answered 11/6, 2018 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.