Caused by java.lang.ClassNotFoundException javax.xml.bind.ValidationException异常

版权声明:本文为本人辛苦原创文章,如果需要转载,请注明出处,谢谢!!! https://blog.csdn.net/sihai12345/article/details/80744012

一、问题描述

Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException
at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1009) ~[na:na]
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:801) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[na:na]
at org.hibernate.validator.internal.engine.ConfigurationImpl.(ConfigurationImpl.java:129) ~[hibernate-validator-
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.ValidationException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[na:na]

二、问题分析

JAXB API是java EE 的API,因此在java SE 9.0 中不再包含这个 Jar 包。
java 9 中引入了模块的概念,默认情况下,Java SE中将不再包含java EE 的Jar包
而在 java 6/7 / 8 时关于这个API 都是捆绑在一起的

三、解决方案

引入下面依赖即可

jaxb-api maven地址:http://mvnrepository.com/artifact/javax.xml.bind/jaxb-api

jaxb-impl maven地址:http://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl

jaxb-core maven地址:http://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core

activation maven地址:http://mvnrepository.com/artifact/javax.activation/activation

<dependency>
     <groupId>javax.xml.bind</groupId>
     <artifactId>jaxb-api</artifactId>
     <version>2.3.0</version>
 </dependency>
 <dependency>
     <groupId>com.sun.xml.bind</groupId>
     <artifactId>jaxb-impl</artifactId>
     <version>2.3.0</version>
 </dependency>
 <dependency>
     <groupId>com.sun.xml.bind</groupId>
     <artifactId>jaxb-core</artifactId>
     <version>2.3.0</version>
 </dependency>
 <dependency>
     <groupId>javax.activation</groupId>
     <artifactId>activation</artifactId>
     <version>1.1.1</version>
 </dependency>

如果加入依赖之后,还是出现这样的问题的话,可能是你的工程没有更新,重新build一下,然后把artifacts的工程删除后,再加载一下就好了!

参考:https://blog.csdn.net/simba1949/article/details/79899431

阅读更多

没有更多推荐了,返回首页