Spring Kafka 2.9.3 NoClassDefFound - AlterIsrRequest$Builder on EmbeddedKafka Start up - spring-kafka

Trying to upgrade the springboot application which uses spring kafka to version 2.9.3 from 2.8.4.
I have followed the instructions here to pulldown kafka-client version 3.2.3 as a separate dependency.
My dependencies looks like this
implementation("org.springframework.kafka:spring-kafka:2.9.3") {
exclude group: "org.apache.kafka", module: "kafka-streams"
exclude group: "org.apache.kafka", module: "kafka-clients"
}
implementation("org.apache.kafka:kafka-clients:3.2.3")
testImplementation("org.springframework.kafka:spring-kafka-test:2.9.3")
When I try to kick off a test which makes use of EmbeddedKafka.
I am getting this NoClassDefFound error
Caused by: java.lang.NoClassDefFoundError: org/apache/kafka/common/requests/AlterIsrRequest$Builder
at kafka.server.KafkaServer.startup(KafkaServer.scala:313)
at kafka.utils.TestUtils$.createServer(TestUtils.scala:177)
at kafka.utils.TestUtils$.createServer(TestUtils.scala:172)
at kafka.utils.TestUtils.createServer(TestUtils.scala)
at org.springframework.kafka.test.EmbeddedKafkaBroker.afterPropertiesSet(EmbeddedKafkaBroker.java:350)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
... 87 more
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.requests.AlterIsrRequest$Builder
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 94 more
I think I am missing a dependency?

You have a version mis-match between the kafka-clients and other kafka jars. All kafka jars must be the same version since the server uses classes from the clients jar.
I don't see AlterIsrRequest in jars since 3.1.2 - so it looks like, somehow, you have older kafka server jars on the class path.
spring-kafka-test:2.9.3 should pull in 3.2.3 transitively.
Since you are using Spring Boot, it will pull in 3.1.2 instead.
See the documentation (https://docs.spring.io/spring-kafka/docs/2.9.3/reference/html/#update-deps) for how to override the dependencies when using Spring Boot.

Related

Servlet class org.restlet.ext.servlet.ServerServlet is not a jakarta.servlet.Servlet

What could be causing this error?
Caused by: jakarta.servlet.UnavailableException: Servlet class org.restlet.ext.servlet.ServerServlet is not a jakarta.servlet.Servlet
at org.eclipse.jetty.servlet.ServletHolder.checkServletType (ServletHolder.java:499)
at org.eclipse.jetty.servlet.ServletHolder.doStart (ServletHolder.java:377)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:96)
at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$2 (ServletHandler.java:699)
at java.util.stream.SortedOps$SizedRefSortingSink.end (SortedOps.java:357)
at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining (StreamSpliterators.java:312)
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining (Streams.java:735)
at java.util.stream.ReferencePipeline$Head.forEach (ReferencePipeline.java:658)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)
I'm running the web app from mvn jetty:run plugin
jakarta.servlet.UnavailableException: Servlet class [...] is not a jakarta.servlet.Servlet
The jakarta.servlet.Servlet is part of Servlet API version 5.0 which in turn is part of Jakarta EE version 9. This can thus only mean that the servlet class specified in [...] is NOT compiled against Servlet API version 5.0, but against an older version.
You have 2 options:
Upgrade the servlet class specified in [...] to a Servlet API version 5.0 compatible one.
Or, downgrade the servlet container from Servlet API version 5.0 to a previous version, at least the one matching the target Servlet API version of the servlet class specified in [...].
The technical reason is that during the step from Java/Jakarta EE 8 to Jakarta EE 9 all javax.* packages have been renamed to jakarta.* packages. So there is no backwards compatibility anymore since Jakarta EE 9.
When we translate the above facts to your specific situation, your only option is to downgrade the Jetty servlet container to a Servlet 4.0 compatible version. This is because the 3rd party library "Restlet" has currently no Servlet 5.0 compatible version available at all. According to Jetty's version table, Jetty 11.x is Jakarta EE 9 targeted, so you need Jetty version 10.x or older.
Alternatively, you can drop Restlet altogether and use Jersey instead. It has currently a Jakarta EE 9 compatible version available.
See also:
Jetty versions
Getting java.lang.ClassNotFoundException: jakarta.servlet.Filter on Maven/Jersey web service while running on Tomcat 9
I was trying to run a Maven application inside a Wildfly server
I installed 20.0.1.Final, the last version before Jakarta

Can't deploy war because ClassCastException: org.hibernate.jpa.HibernatePersistenceProvider incompatible javax.persistence.spi.PersistenceProvider

I got this error even i have created a shared lib on was 9, this lib contains all the hibernate 5.4.3 dependency including javax.persistence 2.2
Do you really needs JPA 2.2 ?
I was able to deploy my EAR under WAS 9 using hibernate 5.2.17 (starting from 5.3 hibernate is JPA 2.2 compliant)
WAS 9 it seems compatible only with JPA 2.0 and JPA 2.1
I created the shared lib using following lists of jars
E:\hibernate-release-5.2.17.Final\lib\envers\hibernate-envers-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\jpa-metamodel-generator\hibernate-jpamodelgen-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\c3p0\c3p0-0.9.5.2.jar
E:\hibernate-release-5.2.17.Final\lib\optional\c3p0\hibernate-c3p0-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\c3p0\mchange-commons-java-0.2.11.jar
E:\hibernate-release-5.2.17.Final\lib\optional\ehcache\ehcache-2.10.3.jar
E:\hibernate-release-5.2.17.Final\lib\optional\ehcache\hibernate-ehcache-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\ehcache\slf4j-api-1.7.7.jar
E:\hibernate-release-5.2.17.Final\lib\optional\infinispan\hibernate-infinispan-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\infinispan\infinispan-commons-8.2.5.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\infinispan\infinispan-core-8.2.5.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\infinispan\jboss-marshalling-osgi-1.4.10.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\infinispan\jgroups-3.6.7.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\proxool\hibernate-proxool-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\optional\proxool\proxool-0.8.3.jar
E:\hibernate-release-5.2.17.Final\lib\osgi\byte-buddy-1.6.14.jar
E:\hibernate-release-5.2.17.Final\lib\osgi\hibernate-osgi-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\osgi\javax.interceptor-api-1.2.jar
E:\hibernate-release-5.2.17.Final\lib\osgi\org.osgi.compendium-4.3.1.jar
E:\hibernate-release-5.2.17.Final\lib\osgi\org.osgi.core-4.3.1.jar
E:\hibernate-release-5.2.17.Final\lib\required\antlr-2.7.7.jar
E:\hibernate-release-5.2.17.Final\lib\required\classmate-1.3.0.jar
E:\hibernate-release-5.2.17.Final\lib\required\dom4j-1.6.1.jar
E:\hibernate-release-5.2.17.Final\lib\required\hibernate-commons-annotations-5.0.1.Final.jar
E:\hibernate-release-5.2.17.Final\lib\required\hibernate-core-5.2.17.Final.jar
E:\hibernate-release-5.2.17.Final\lib\required\jandex-2.0.3.Final.jar
E:\hibernate-release-5.2.17.Final\lib\required\javassist-3.22.0-GA.jar
E:\hibernate-release-5.2.17.Final\lib\required\jboss-logging-3.3.1.Final.jar
It is important on the Shared Lib def to check "Class Loading - Use an isolated class loader for this shared library"
and on the Applicatiion --> Class Loader --> Class Loader Order --> select Classes Loaded with Local Class Loader First (Parent Last)
I'm looking too to use up-to-date Hibernate 5.4.x (stable) and in the future the 6.x.. but having similar issue
If eventually you was able to use Hibernate 5.4.x.. can you share ?
Regards

Need to provide addtional jars to for xsbt-web-plugin container

I am trying to run my war file using xsbt-web-plugin. My war itself does not contain tomcat-jdbc-pool jar and javax-servlet-api. I tried using container configuration. But sbt complains configuration does not exist.
If I use provided configuration, webapp-runner fails.
I am sure I am missing something. But unable to figure it out.
WARNING: Failed to register in JMX: [javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSourceFactory]]
What version of xsbt-web-plugin are you using? Can you post the contents of your sbt build configuration?
The Tomcat plugin in xsbt-web-plugin relies on webapp-runner, which does not appear to bundle the tomcat-jdbc library. You can add it via containerLibs in Tomcat:
enablePlugins(TomcatPlugin)
containerLibs in Tomcat += "org.apache.tomcat" % "tomcat-jdbc" % "8.5.15"

Export package in OSGi Bundle

I have an OSGi Bundle and a servlet. Now I want to access the bundle from the servlet. For that purpose I use the following in the servlet:
#Resource
BundleContext context
...
ServiceReference ref = context.getServiceReference("package.MyOSGiServiceInterface");
MyOSGiServiceInterface service = context.getService(ref);
The Problem is that my servlet doesn't know MyOSGiServiceInterface 'cause that is defined in the OSGiBundle. In Eclipse I added a reference to the bundle Project in my Build Path. But at runtime it obviously can't find it.
To solve that Problem I played around with
(in bundle manifest)
Export-Package: package-of-osgi-service-interface
(in servlet manifest)
Import-Package: package-of-osgi-service-Interface
Dependencies: ...,deployment.MyBundle
But I couldn't solve it.
Whats the missing step? How can I tell JBoss to add the package containing MyOSGiServiceInterface in OSGiBundle to the class path?
Thanks for answers!
(JBoss AS 7.1.1)
--> error message <--
Eventually I solved it. I had to put the right combination of settings together to reach my goal:
Deploy the bundle per: File - Export - "Deployable plug-ins and fragments" into folder: "jboss/standalone/deployments"
Bundle-Manifest:
Bundle-SymbolicName: TestBundle
Bundle-Version: 1.0.0
Export-Package: "package-which-includes-my-service"
Servlet-Manifest:
Dependencies: org.osgi.core,org.jboss.osgi.framework,deployment.TestBundle:1.0.0
Import-Package: "package-which-includes-my-service"

java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException in JBoss AS 7

I am testing JBoss AS 7 prior to deployment with a .war file of an app running in a different server.
I get this error when I try to log onto the database via the app:
SEVERE [] (http--0.0.0.0-8080-4) java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException from [Module "deployment.app.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
In some forums, they suggest adding the commons-codec jar, but I already have it in JBoss, right? (in here: jboss-as-7.1.1.Final/modules/org/apache/commons/codec/main/commons-codec-1.4.jar)
OSGi is not activated, frankly I have no idea to what purpose it serves, but when I try to activate it it messes with my war as it fails to deploy...
I have JDK, but no JRE if that's any help.
JBoss AS 7 does not use OSGi by default for modular class loading. It uses JBoss Modules so this has nothing to do with OSGi.
What you need to do if you want to use the commons-codec provided with JBoss AS 7 is add a dependency to your deployment.
Modules are not visible by your artefact classes automatically. You have three possibilities:
Define a global module in your standalone.xml
http://javahowto.blogspot.de/2012/09/how-to-create-global-modules-in-jboss.html
This module will be used by all artefacts you are deploying on Jboss.
Put it into your war artefact, into the lib folder. You can do that with Maven.
Define an explicit dependency within your Manifest. https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7
Section Dependencies: Manifest Entries

Resources