Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Upgrade Java 8 to Java 11 and kafka conflicts

 
Ranch Hand
Posts: 276
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

We upgraded one of the spring boot-based microservice to Java 11 from 8. Post-up-gradation facing some issue with KafkaConfiguration bean initialization issue. Maven build is getting success, but when trying to execute the application facing the below error stack trace. The Kafka version used is kafka_2.13-2.7.0 and ensured that Java 11 is installed as Java_home with echo $JAVA_VERSION.mohammedsardar$ echo $JAVA_HOME/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home

Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:139) ~[jackson-module-jaxb-annotations-2.9.10.jar:2.9.10]

Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlElement
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:an]

Anyone has seen this issue before? Any idea will really help me a lot.  Thanks.
 
Marshal
Posts: 8198
585
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Read this article written by one of coderanch moderators: https://www.jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond/

I'm not entirely sure I know all the details about your scenario, but that sounds similar to what's in the article.
 
Sheriff
Posts: 22567
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's exactly the same thing. In Java 11, all of the so-called JEE modules were removed from the SDK. One of those is JAXB, and that's the one that's missing, as you can see from the root package javax.xml.bind. Jesper's article explains both the issue and the proper solution.

Just one warning with the jakarta.xml.bind dependency (and its implementation). The 3.x versions changed the root package from javax to jakarta, so you'll need to stick with version 2.3.x. And where Jesper mentions com.sun.xml.bind:jaxb-impl, I prefer org.glassfish.jaxb:jaxb-runtime.
 
Mohammed Sardar.
Ranch Hand
Posts: 276
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for sharing throughts and link. For some unknown reason, I couldn't download the below dependency either from nexus or from maven repos. I ensured I follow the proper URL in the .m2 folder settings.xml. After spending some long hours, manually downloaded the below jar and added it to the local maven repo. Then tried to execute the application but still ended up with the error.  The screenshot shows, manually added XML. bind dependency to the external library. Maven build was a success. Do we have any debugging techniques to reach the root cause of the issue? Any issue in dependency setup?

I observe looks something different from the shown error in the link. Actually, I'm getting Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:139) ~[jackson-module-jaxb-annotations-2.9.10.jar:2.9.10]

Screenshot-2022-01-09-at-1.10.52-PM.png
[Thumbnail for Screenshot-2022-01-09-at-1.10.52-PM.png]
 
Mohammed Sardar.
Ranch Hand
Posts: 276
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sharing some more lengthy stack traces for better understanding. some of the package names are masked due to security reason.

Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xxx.orc.payments.api.config.KafkaConfiguration$$EnhancerBySpringCGLIB$$b11914e9]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
2022-01-09T13:08:45.562+05:30 ERROR [org-payments,,,] 4880 --- [TraceId:] [UserId:] [UserScope:] [           main] o.s.b.SpringApplication                  : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaConfiguration'
payments/api/config/KafkaConfiguration.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:304) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:285) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1340) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1186) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:139) ~[jackson-module-jaxb-annotations-2.9.10.jar:2.9.10]
at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:126) ~[jackson-module-jaxb-annotations-2.9.10.jar:2.9.10]
at com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule.setupModule(JaxbAnnotationModule.java:90) ~[jackson-module-jaxb-annotations-2.9.10.jar:2.9.10]
at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:751) ~[jackson-databind-2.9.10.1.jar:2.9.10.1]
at com.fasterxml.jackson.databind.ObjectMapper.registerModules(ObjectMapper.java:951) ~[jackson-databind-2.9.10.1.jar:2.9.10.1]
at com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules(ObjectMapper.java:1029) ~[jackson-databind-2.9.10.1.jar:2.9.10.1]
at com.xxxx.core.messaging.spring.kafka.AbstractKafkaConfiguration.<init>(AbstractKafkaConfiguration.java:61) ~[spring-kafka-support-2.12.0.jar:2.12.0]
at com.xxxx.orc.payments.api.config.KafkaConfiguration.<init>(KafkaConfiguration.java:16) ~[classes/:na]
at com.yyyy.orc.payments.api.config.KafkaConfiguration$$EnhancerBySpringCGLIB$$b11914e9.<init>(<generated>) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:an]
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlElement
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 43 common frames omitted


 
Mohammed Sardar.
Ranch Hand
Posts: 276
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm able to import the dependency after including it in the respective sub-module instead of root pom. I thought the dependency would be inherited from root pom but that didn't work.  I still need to understand why is it so. How the root pom dependencies can be reused in another sub-module pom?
 
Rob Spoor
Sheriff
Posts: 22567
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends where in your root pom you include the dependencies. If it's directly under dependencies (which you shouldn't usually do), then these dependencies should definitely be inherited. If it's under dependencyManagement/dependencies, then those are only declarations of dependencies; you mostly use them for the version, and possibly exclusions. Modules then still need to include the dependency itself, but this time only the groupId and artifactId are needed, the rest is taken from the dependencyManagement.
 
reply
    Bookmark Topic Watch Topic
  • New Topic