Home  >  Forum  >  Spring
Post New Query

[SOLVED-JAVA 9] java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException



Asked on March 01, 2018
Hi, I am getting following exception in my Spring application with Java 9. How to resolve it?

nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 37 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:129)
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:96)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:31)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276)
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:223)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$LocalValidatorFactory.run(ConfigurationPropertiesBindingPostProcessor.java:441)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.getValidator(ConfigurationPropertiesBindingPostProcessor.java:375)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.determineValidator(ConfigurationPropertiesBindingPostProcessor.java:358)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:317)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
... 46 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.ValidationException
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:178)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:142)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 59 common frames omitted



Replied on March 01, 2018
JDK 9 has done some changes for java.xml.bind and other Java EE modules. Let us understand.

1.

JDK 9 has deprecated java.xml.bind module and has removed from default classpath.
@Deprecated(since="9", forRemoval=true)

Module java.xml.bind
Deprecated, for removal: This API element is subject to removal in a future version.


https://docs.oracle.com/javase/9/docs/api/java.xml.bind-summary.html

Java has made plan to remove the Java EE and CORBA modules from Java SE and the JDK after JDK 9 versions. In Java 9 they have only deprecated and have removed it from classpath.

2.

javax.xml.bind is sub package of Module java.xml.bind

So Module javax.xml.bind will not be available on classpath by default in JAVA 9.

Solution:

1. Use --add-modules to add module in classpath.

As Java has not yet removed from module from java 9. Java has only deprecated and does not add javax.xml.bind module on classpath by default.

So if we want to add javax.xml.bind on classpath we can add using following command.


--add-modules java.xml.bind

2. We can use Maven and Gradle to include javax.xml.bind in our project.

Maven

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

Gradle

compile 'javax.xml.bind:jaxb-api:2.3.0'



Find the reference link

http://openjdk.java.net/jeps/8189188


Replied on March 01, 2018
Great. It is working. Thanks.


Replied on July 13, 2018
Thanks! It is useful.
Please update the title with [SOLVED], it will be helpful for more people. 


Write Answer




©2019 concretepage.com | Privacy Policy | Contact Us