ClassNotFoundException:org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder

时间:2018-09-23 12:48:27

标签: java keycloak

尝试创建一个keycloak对象,以使用以下代码向keycloak注册新用户:

 Keycloak keycloak = KeycloakBuilder.builder()
                            .serverUrl(serverUrl)
                            .realm(realm)
                            .grantType(OAuth2Constants.PASSWORD)
                            .clientId(clientId)
                            .clientSecret(clientSecret)
                            .username("someone")
                            .password("someword")
                            .build();

但是出现以下错误:

  带有路径的Servlet [dispatcherServlet]中的

Servlet.service()   []抛出异常[处理程序调度失败;嵌套异常为   java.lang.NoClassDefFoundError:   org / jboss / resteasy / client / jaxrs / ResteasyClientBuilder]并找到根本原因

     

java.lang.ClassNotFoundException:   org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder           在java.net.URLClassLoader.findClass(URLClassLoader.java:381)〜[na:1.8.0_131]           在java.lang.ClassLoader.loadClass(ClassLoader.java:424)〜[na:1.8.0_131]           在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:335)   〜[na:1.8.0_131]           在java.lang.ClassLoader.loadClass(ClassLoader.java:357)〜[na:1.8.0_131]           在org.keycloak.admin.client.Keycloak。(Keycloak.java:58)〜[keycloak-admin-client-4.3.0.Final.jar:4.3.0.Final]           在org.keycloak.admin.client.KeycloakBuilder.build(KeycloakBuilder.java:147)   〜[keycloak-admin-client-4.3.0.Final.jar:4.3.0.Final]           在hello.GreetingController.greeting(GreetingController.java:100)   〜[main /:na]           在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)〜[na:1.8.0_131]

1 个答案:

答案 0 :(得分:2)

请尝试将这些依赖项添加到项目pom中。 依赖关系的版本可能是3.6.0.Final或3.5.0.Final(我不确定您的keycloak-admin-client依赖关系版本。但是,我将keycloak-admin-client 3.0.0.Final与3.5.0.Final一起使用resteasy-client。成功运行。)

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