找不到用于休眠配置的类?

时间:2018-08-13 08:10:10

标签: java hibernate maven tomcat intellij-idea

我正在使用Intellij,Maven,Tomcat,Hibernate和JEE创建一些应用程序。 当我尝试通过Tomcat通过Intellij运行我的应用程序时,webrowser中出现错误:

Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:579)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
    org.apache.jsp.addAdvertisement_jsp._jspService(addAdvertisement_jsp.java:176)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    com.advertisement.entity.AdvertisementDAO.init(AdvertisementDAO.java:29)
    org.apache.jsp.addAdvertisement_jsp._jspService(addAdvertisement_jsp.java:148)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause

java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1352)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
    com.advertisement.entity.AdvertisementDAO.init(AdvertisementDAO.java:29)
    org.apache.jsp.addAdvertisement_jsp._jspService(addAdvertisement_jsp.java:148)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

我的项目结构如下:

enter image description here

当我运行JUnit测试时,所有功能都可以正常工作。

import com.advertisement.entity.Advertisement;
import com.advertisement.entity.AppUser;
import junit.framework.TestCase;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * Unit test for simple App.
 */
public class AppTest extends TestCase {

    public void testAppUser() {
        SessionFactory sessionFactory = new Configuration().configure()
                .buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();

        AppUser user = new AppUser("firstuser");
        session.save(user);

        session.getTransaction().commit();
        session.close();
    }

    public void testAppAdvertisement() {
        SessionFactory sessionFactory = new Configuration().configure()
                .buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();

        Advertisement advertisement = new Advertisement();
        session.save(advertisement);

        session.getTransaction().commit();
        session.close();
    }
}

问题是当我将其部署到Tomcat并在运行之后。在我看来,Tomcat没有看到Hibernate或Hibernate的配置,某些Hibernate配置路径不正确?

0 个答案:

没有答案