简体   繁体   English

实例化休眠配置会引发错误:线程“ main”中的异常java.lang.NoClassDefFoundError:javax / xml / bind / JAXBException

[英]Instantiating a hibernate Configuration throws error: Exception in thread “main” java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

I am fairly new to the hibernate framework and I'm creating a simple application with a Udemy course. 我对休眠框架还很陌生,并且正在使用Udemy课程创建一个简单的应用程序。 I've continually been getting a 'java.lang.NoClassDefFoundError' on the following stack. 我一直在下面的堆栈上得到一个“ java.lang.NoClassDefFoundError”。 It appears that when I create a org.hibernate.cfg.Configuration object the exception is thrown. 似乎当我创建org.hibernate.cfg.Configuration对象时,会引发异常。 Any guidance would be appreciated on how to solve the following issue, is it possible that this hibernate version is buggy and I need to backtrack to a previous version? 任何有关如何解决以下问题的指导将不胜感激,此休眠版本是否有故障,是否需要回溯到以前的版本?

Hibernate-Core Version: 5.3.0.Final 休眠核心版本:5.3.0。最终版

Hibernate-Annotations: 3.5.6.Final 休眠注释:3.5.6。最终

My-SQL Server Version: 8.0.12 My-SQL Server版本:8.0.12

DEBUG - Logging Provider: org.jboss.logging.Log4jLoggerProvider
DEBUG - Adding Integrator [org.hibernate.cfg.beanvalidation.BeanValidationIntegrator].
DEBUG - Adding Integrator [org.hibernate.secure.spi.JaccIntegrator].
DEBUG - Adding Integrator [org.hibernate.cache.internal.CollectionCacheInvalidator].
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
    at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:86)
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:123)
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:118)
    at com.dataPack.data.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
    at com.dataPack.data.HibernateUtil.<clinit>(HibernateUtil.java:10)
    at com.dataPack.data.Application.main(Application.java:9)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 7 more

Here is the HibernateUtil class I created to build the sessionFactory. 这是我创建的用于构建sessionFactory的HibernateUtil类。

package com.dataPack.data;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;


public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {

        Configuration configuration = null;
        try {
            configuration = new Configuration();

            return configuration
                    .buildSessionFactory(new StandardServiceRegistryBuilder()
                            .applySettings(configuration.getProperties())
                                .build());

        } catch(Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Issue Building Session Factory!");
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

Here is the hibernate.properties file we are suppose to use. 这是我们应该使用的hibernate.properties文件。

hibernate.connection.username=user
hibernate.connection.password=password
hibernate.connection.url=jdbc:mysql://localhost:3306/ifinances
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

Since this project is known to work, it's likely that others have used a different Java version as the jaxb Apis were removed from Java SE. 由于该项目有效,因此其他人可能使用了其他Java版本,因为jaxb Apis已从Java SE中删除。 There are multiple ways to address this (as detailed in How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9 ) but the most reliable is to add the jaxb API dependency (groupId javax.xml.bind, artifactId jaxb-api - https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api/2.3.0 ) to the pom.xml or gradle build file. 有多种方法可以解决此问题(如如何解决java.lang.NoClassDefFoundError:Java 9中的javax / xml / bind / JAXBException中所述 ),但是最可靠的方法是添加jaxb API依赖项(groupId javax.xml.bind, artifactId jaxb-api- https: //mvnrepository.com/artifact/javax.xml.bind/jaxb-api/2.3.0)到pom.xml或gradle构建文件。

Then rebuild and if you still hit ClassNotFound errors then see https://stackoverflow.com/a/43574427/9705485 然后重新构建,如果仍然遇到ClassNotFound错误,请参见https://stackoverflow.com/a/43574427/9705485

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 泽西Servlet-java.lang.NoClassDefFoundError:javax / xml / bind / JAXBException - Jersey Servlet - java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException 如何解决 java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException - How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException 如何解决错误:java:java.lang.NoClassDefFoundError:javax/xml/bind/JAXBException - How to resolve Error:java: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException 线程“主”java.lang.NoClassDefFoundError 中的异常:javax/xml/bind/annotation/XmlSchema - Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema 线程“main”中的异常java.lang.ExceptionInInitializerError引起:javax.xml.bind.DataBindingException:javax.xml.bind.JAXBException - Exception in thread “main” java.lang.ExceptionInInitializerError Caused by: javax.xml.bind.DataBindingException: javax.xml.bind.JAXBException java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException 更新到 Android Studio 4.2 后 - java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException after updating to Android Studio 4.2 xades4j.utils.XadesProfileResolutionException:java.lang.NoClassDefFoundError:javax/xml/bind/JAXBException SoapUI - xades4j.utils.XadesProfileResolutionException: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException SoapUI 线程“main”中的异常 java.lang.NoClassDefFoundError: javax/jms/MessageListener - Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/MessageListener 线程“主”中的异常java.lang.NoClassDefFoundError:javax / persistence / Cacheable - Exception in thread “main” java.lang.NoClassDefFoundError:javax/persistence/Cacheable Java在主线程java.lang.NoClassDefFoundError中引发异常 - Java Throws exception in thread main java.lang.NoClassDefFoundError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM