我正在尝试在Scala中为keycloak实现一个事件侦听器,我将其用作胖子,但是当我添加kryo序列化时,我得到了ClassNotFoundException
现在,我将项目从sbt
移到了maven,以便按照beercloak示例的结构制作一个ear
,已经部署了事件侦听器,但是我不确定如何将Scala库包含在依赖项中。
这是我的jboss-deployment-structure
:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<module-alias name="deployment.keycloak-listener"/>
</deployment>
<sub-deployment name="keycloak-listener.jar">
<dependencies>
<!--<module name="org.scala-lang-scala-library"/>-->
<!--<module name="org.scala-lang"/>-->
<!-- I don't know how to add scala library -->
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
这是我的ear
的结构:
META-INF/
META-INF/MANIFEST.MF
META-INF/application.xml
META-INF/jboss-deployment-structure.xml
META-INF/maven/
META-INF/maven/com.example/
META-INF/maven/com.example/keycloak-listener-ear/
META-INF/maven/com.example/keycloak-listener-ear/pom.properties
META-INF/maven/com.example/keycloak-listener-ear/pom.xml
keycloak-listener.jar
lib/
lib/com.esotericsoftware-kryo-4.0.2.jar
lib/com.esotericsoftware-kryo-shaded-4.0.2.jar
lib/com.esotericsoftware-minlog-1.3.0.jar
lib/com.esotericsoftware-reflectasm-1.11.3.jar
lib/com.fasterxml.jackson.core-jackson-annotations-2.9.0.jar
lib/com.fasterxml.jackson.core-jackson-core-2.9.5.jar
lib/com.fasterxml.jackson.core-jackson-databind-2.9.5.jar
lib/com.github.luben-zstd-jni-1.3.7-1.jar
lib/com.twitter-chill-java-0.9.3.jar
lib/com.twitter-chill_2.12-0.9.3.jar
lib/de.javakaffee-kryo-serializers-0.45.jar
lib/joda-time-joda-time-2.10.1.jar
lib/org.apache.kafka-kafka-clients-2.1.1.jar
lib/org.bouncycastle-bcpkix-jdk15on-1.60.jar
lib/org.bouncycastle-bcprov-jdk15on-1.60.jar
lib/org.keycloak-keycloak-common-5.0.0.jar
lib/org.keycloak-keycloak-core-5.0.0.jar
lib/org.lz4-lz4-java-1.5.0.jar
lib/org.objenesis-objenesis-2.5.1.jar
lib/org.ow2.asm-asm-5.0.4.jar
lib/org.scala-lang-scala-library-2.12.8.jar
lib/org.slf4j-slf4j-api-1.7.25.jar
lib/org.xerial.snappy-snappy-java-1.1.7.2.jar
这是一个例外:
16:20:26,161 ERROR [org.keycloak.services] (default task-3) KC-SERVICES0085: Failed to send type to com.example.listener.KeycloakListenerProvider@4d3f57a9: java.lang.RuntimeException: java.lang.ClassNotFoundException: scala.Function0 from [Module "deployment.keycloak-server.war" from Service Module Loader]
at com.twitter.chill.ResourcePool.borrow(ResourcePool.java:44)
at com.twitter.chill.KryoPool.toBytesWithClass(KryoPool.java:114)
at com.example.kafka.KryoSerializationSupport.serialize(KryoSerialization.scala:56)
at com.example.kafka.KryoSerializationSupport.serialize$(KryoSerialization.scala:55)
at com.example.kafka.KryoSerializer.serialize(KryoSerialization.scala:19)
at org.apache.kafka.common.serialization.Serializer.serialize(Serializer.java:60)
at com.example.kafka.KryoSerializer.serialize(KryoSerialization.scala:14)
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:877)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:839)
at com.example.kafka.KafkaEventProducer$.send(KafkaEventProducer.scala:43)
at com.example.listener.KeycloakListenerProvider.onEvent(KeycloakListenerProvider.scala:62)
at org.keycloak.services.resources.admin.AdminEventBuilder.send(AdminEventBuilder.java:248)
at org.keycloak.services.resources.admin.AdminEventBuilder.success(AdminEventBuilder.java:227)
at org.keycloak.services.resources.admin.UserResource.deleteUser(UserResource.java:528)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:509)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:399)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:363)
at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:365)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:337)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:137)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:106)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:132)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:106)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:132)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:106)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:132)
at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:100)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:443)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:233)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:139)
at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:142)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:219)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:227)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:90)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: scala.Function0 from [Module "deployment.keycloak-server.war" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.twitter.chill.KryoBase.$anonfun$functions$1(KryoBase.scala:41)
at com.twitter.chill.KryoBase.$anonfun$functions$1$adapted(KryoBase.scala:41)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
at scala.collection.immutable.Range.foreach(Range.scala:158)
at scala.collection.TraversableLike.map(TraversableLike.scala:237)
at scala.collection.TraversableLike.map$(TraversableLike.scala:230)
at scala.collection.AbstractTraversable.map(Traversable.scala:108)
at com.twitter.chill.KryoBase.<init>(KryoBase.scala:41)
at com.twitter.chill.EmptyScalaKryoInstantiator.newKryo(ScalaKryoInstantiator.scala:36)
at com.twitter.chill.ScalaKryoInstantiator.newKryo(ScalaKryoInstantiator.scala:73)
at com.example.kafka.KryoPoolFactory$DefaultKryoInstantiator.newKryo(KryoSerialization.scala:85)
at com.example.kafka.KryoPoolFactory$DefaultKryoInstantiator.newKryo(KryoSerialization.scala:83)
at com.twitter.chill.KryoPool$2.newInstance(KryoPool.java:59)
at com.twitter.chill.KryoPool$2.newInstance(KryoPool.java:57)
at com.twitter.chill.ResourcePool.borrow(ResourcePool.java:37)
... 88 more