Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError javax/xml/bind/annotation/XmlElement #361

Closed
piomin opened this issue Sep 18, 2023 · 9 comments
Closed

NoClassDefFoundError javax/xml/bind/annotation/XmlElement #361

piomin opened this issue Sep 18, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@piomin
Copy link

piomin commented Sep 18, 2023

After adding dependencies springwolf-kafka and springwolf-ui app doen't start. Here's the exception:

11:31:12.645 --- [           main] : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: javax/xml/bind/annotation/XmlElement
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1155)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
	at pl.piomin.stock.StockApp.main(StockApp.java:25)
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
	at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:137)
	at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:124)
	at com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule.setupModule(JaxbAnnotationModule.java:98)
	at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:879)
	at com.fasterxml.jackson.databind.ObjectMapper.registerModules(ObjectMapper.java:1081)
	at com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules(ObjectMapper.java:1165)
	at org.hibernate.type.format.jackson.JacksonXmlFormatMapper.createXmlMapper(JacksonXmlFormatMapper.java:48)
	at org.hibernate.type.format.jackson.JacksonXmlFormatMapper.<init>(JacksonXmlFormatMapper.java:38)
	at org.hibernate.type.format.jackson.JacksonIntegration.<clinit>(JacksonIntegration.java:17)
	at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.lambda$determineJsonFormatMapper$6(SessionFactoryOptionsBuilder.java:785)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:220)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:180)
	at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.determineJsonFormatMapper(SessionFactoryOptionsBuilder.java:781)
	at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.<init>(SessionFactoryOptionsBuilder.java:298)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.<init>(SessionFactoryBuilderImpl.java:48)
	at org.hibernate.boot.internal.DefaultSessionFactoryBuilderService.createSessionFactoryBuilder(DefaultSessionFactoryBuilderService.java:26)
	at org.hibernate.boot.internal.MetadataImpl.getSessionFactoryBuilder(MetadataImpl.java:170)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1451)
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:75)
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1817)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766)
	... 15 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlElement
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 40 common frames omitted

Other dependencies used in the project:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
@piomin piomin added the bug Something isn't working label Sep 18, 2023
@github-actions
Copy link

Welcome to Springwolf. Thanks a lot for reporting your first issue. Please check out our contributors guide and feel free to join us on discord.

@stavshamir
Copy link
Member

Hi @piomin, thanks for reporting this issue.
What version of Spring Boot and Java are you using?

@piomin
Copy link
Author

piomin commented Sep 19, 2023

Spring 3.1.3
Java 17

@stavshamir
Copy link
Member

It doesn't seem related to Springwolf, please try adding the following dependency and see if the problem is solved:

<dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
</dependency>

@piomin
Copy link
Author

piomin commented Sep 19, 2023

Yes, it solves. But is it the right approach since I already have jakarta.xml-bind-api:4.0.0 included ?

[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.1.3:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:3.1.3:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.1.3:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.8.0:test
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:runtime
[INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:2.1.2:runtime

@timonback
Copy link
Member

I would have to look at the dependency tree again, but I think swagger-inflector still uses javax.

We plan to remove the dependency in the next release, which should also fix your problem.

@deepakdaneva
Copy link

Yes, it solves. But is it the right approach since I already have jakarta.xml-bind-api:4.0.0 included ?

[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.1.3:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:3.1.3:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.1.3:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.8.0:test
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:runtime
[INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:2.1.2:runtime

I also think the same @piomin, if jakarta.xml-bind-api is on the classpath this error should not be thrown.
I am also facing this error below are the details:

  1. Spring Boot: 3.1.5
  2. Springwolf Kafka: 0.12.1
  3. Java: 17

@timonback
Copy link
Member

Hi @deepakdaneva
comments on closed issues are difficult to see. Please create a new issue - feel free to link to this one as a reference.

Have you tried the latest Springwolf version? It contains many improvements, including the fix for the original issue.

@timonback
Copy link
Member

Recently, it was discovered that this may happen when swagger-core is used instead of swagger-core-jakarta.
See: springwolf/springwolf.github.io#94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants