2

我的项目一直在工作,直到我尝试将字符编码设置为 UTF-8。我将该<property name="hibernate.connection.characterEncoding">utf8</property>行添加到我的hibernate.cfg.xml. 现在重新启动计算机后,我收到了这个奇怪的错误:

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at dal.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:15)
    at dal.hibernate.HibernateDAOFactory.getSession(HibernateDAOFactory.java:25)
    at dal.hibernate.HibernateUserDAO.authenticate(HibernateUserDAO.java:23)
    at controller.servlet.LogIn.doPost(LogIn.java:63)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    ... 22 more

堆栈中的前四个类是我的类。

我看到new Configuration();调用导致错误,但我在 WEB-INF/lib 中有必要的 JAR-s:

  • antlr-2.7.7.jar
  • dom4j-1.6.1.jar
  • hibernate-commons-annotations-4.0.1.Final.jar
  • hibernate-core-4.1.9.Final.jar
  • hibernate-jpa-2.0-api-1.0.1.Final.jar
  • javassist-3.17.1-GA.jar
  • jboss-logging-3.1.0.GA.jar
  • jboss-transaction-api_1.1_spec-1.0.0.Final.jar
  • mysql-connector-java-5.1.18-bin.jar

这是配置 XML:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/web_projekt</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">******</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="hibernate.connection.characterEncoding">utf8</property>
        <property name="show_sql">true</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>

        <!-- Mapping files -->
        <mapping resource="core/bean/tables.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

你知道有什么问题吗?

4

0 回答 0