我在Java EE(JAX-RS 2.1 / Resteasy,EJB,CDI,...)中编写的REST应用程序必须能够在Keycloak 2.5.5中创建一个keycloak用户。要运行我的应用程序,我使用WildFly 10.1.0服务器。
要创建keycloak用户,我想使用Keycloak公布的管理REST API。因此,我已向build.gradle
添加了以下依赖项:
compile group: 'org.keycloak', name: 'keycloak-admin-client', version: '3.3.0.Final'
之后(仅添加依赖项)当我在WildFly上部署我的应用程序时,我发现错误是由于:
java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.keycloak.admin.client.resource.RealmsResource
有时由于:
java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.keycloak.admin.client.resource.ServerInfoResource
这是关于第一个错误的完整堆栈跟踪:
08:14:14,505 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 86) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./myapp: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./myapp: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.keycloak.admin.client.resource.RealmsResource
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.keycloak.admin.client.resource.RealmsResource
at org.jboss.resteasy.spi.metadata.ResourceBuilder.constructor(ResourceBuilder.java:692)
at org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.registered(POJOResourceFactory.java:42)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:208)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:194)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:180)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:157)
at org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:76)
at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:409)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:250)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:113)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)
at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:250)
at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:133)
at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:546)
at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:517)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:559)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:101)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
... 6 more
08:14:14,511 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "myapp.war")]) - failure description: {
"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./myapp" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./myapp: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.keycloak.admin.client.resource.RealmsResource
Caused by: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.keycloak.admin.client.resource.RealmsResource"},
"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./myapp"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined
可能很重要,build.gradle
中存在关于JAX-RS / Resteasy的依赖关系:
compile( 'javax:javaee-api:7.0') {
exclude group: 'javax.ws.rs', module: 'javax.ws.rs-api'
}
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1'
compile group: 'org.jboss.resteasy', name: 'resteasy-servlet-initializer', version: '3.1.4.Final'
//compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.4.Final'
compile group: 'org.jboss.resteasy', name: 'resteasy-jaxb-provider', version: '3.1.4.Final'
compile group: 'org.jboss.resteasy', name: 'resteasy-multipart-provider', version: '3.1.4.Final'
当我使用resteasy-jaxrs
lib而不是resteasy-servlet-initializer
时,我可以在没有任何问题的情况下部署应用程序但是应用程序的端点无法正常工作(找不到错误)。