java.lang.NoClassDefFoundError:无法初始化类xxx.xxx.xxx.HibernateUtil

普里扬

我在此添加了web.xml的源代码

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <display-name>ussd</display-name>
    <servlet>
        <servlet-name>init</servlet-name>
        <jsp-file>/init.jsp</jsp-file>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <context-param>
        <param-name>javax.ws.rs.core.Application</param-name>
        <param-value>com.dialog.mife.ussd.api.USSDApplication</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.providers</param-name>
        <param-value>com.dialog.mife.ussd.exception.NotFoundException</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/</param-value>
    </context-param>
    <listener>
        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    </listener>
    <servlet>
        <servlet-name>Resteasy</servlet-name>
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Resteasy</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/webresources/*</url-pattern>
    </servlet-mapping>
</web-app>

Hibernate.cfg.xml。我的Web服务项目与Jersey + Hibernate一起使用。

    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>   
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">xxx</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/USSD</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>   
        <property name="hbm2ddl.auto">update</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="connection.pool_size">1</property>
        <property name="hibernate.connection.autocommit">true</property>
        <mapping class="com.xxx.xxx.xxx.xxx.Application" />

    </session-factory>
</hibernate-configuration>

这是HibernateUtil类

public class HibernateUtil {
    private static final SessionFactory sessionFactory;
    static {
        try {
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new ExceptionInInitializerError(ex);
        }
    }

这是我添加了Hibernate最新的jar文件的错误。[ hibernate-core-4.3.7.Final.jar ]

SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: Could not initialize class com.dialog.mife.ussd.util.HibernateUtil
    at org.apache.jsp.init_jsp.jspInit(init_jsp.java:23)
    at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:48)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:138)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Nov 11, 2014 2:06:11 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /ussd threw load() exception
java.lang.NoClassDefFoundError: Could not initialize class com.dialog.mife.ussd.util.HibernateUtil
    at org.apache.jsp.init_jsp.jspInit(init_jsp.java:23)
    at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:48)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:138)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

请帮助我解决这个问题,谢谢

勇敢

初始化SessionFactory失败时可能会发生这种错误您已经提到您正在使用hibernate-core-4.3.7初始化的SessionFactory方式不适用于该版本。使用Hibernate 3.x版或更改初始化方式SessionFactory以下是在中建立会话工厂的正确方法Hibernate 4.x +

Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().
applySettings(configuration.getProperties());
SessionFactory factory = configuration.buildSessionFactory(builder.build());

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

异常在线程“主” java.lang.IllegalArgumentException异常:安装方案“HTTP” URI的“http://xxx.xxx.xxx.xxx:xxxx”没有NetworkModule

Android的工作室:拆箱的“XXX”可能会产生“显示java.lang.NullPointerException”

java.lang.UnsatisfiedLinkError:本机库XXX.so已加载到另一个类加载器中

java.lang.NoClassDefFoundError:无法初始化类java.awt.Toolkit

java.lang.NoClassDefFoundError:无法初始化类XXX

Java SE标准类无法解析导入XXX

Java-奇怪的静态字符串行为-新的String(“ xxx”)与“ xxx”

网络安全策略不允许与XXX.XXX.XXX.XXX进行CLEARTEXT通信

java.lang.IllegalArgumentException:名称为[xxx]的参数不存在

WARN TaskSetManager:丢失的任务xxx:java.lang.ArrayIndexOutOfBoundsException:1-Scala

Spark 2.2非法模式组件:XXX java.lang.IllegalArgumentException:非法模式组件:XXX

春季:java.lang.NoClassDefFoundError:无法初始化类

拨打tcp:查找xxx.xxx.xxx.xxx:没有这样的主机

错误“无法在广告素材中使用该视频。视频ID XXX,XXX,XXX,XXX,XXX可能不是视频ID,或者您可能没有观看权限”

无法读取未定义的属性“ xxx.xxx”

找不到模块xxx,xxx要求

按XXX排序按钮

在Java中,如何将数字格式化为字符串,使其格式为“ xxx.xxx.xxx,yy”?

线程“主”中的异常java.lang.Error:未解决的编译问题:本地变量xxx可能尚未初始化

资源“ xxx”无法解析

C ++中的XXX注释

SQLSTATE [HY000] [2003]无法连接到“ XXX.XXX.XXX.XXX”上的MySQL服务器(60)

MySQL WorkBench无法以root用户[主机到Vmware]连接到XXX.XXX.XXX上的Mysql

Java错误:XXX类型中的XXX方法不适用于自变量

找不到方法XXX.YYY中引用的类XXX

“ route add -host xxx.xxx.xxx.xxx dev eth0:1”的含义

输出端口上的XXX

java.lang.ClassCastException:android.os.BinderProxy无法强制转换为xxx $ LocalBinder

错误:“ xxx”不是类型