java.lang.NoSuchMethodError:org.hibernate.integrator.internal.IntegratorServiceImpl。<init>(Ljava / util / LinkedHashSet; Lorg / hibernate / service / class $

时间:2017-10-02 10:28:32

标签: hibernate maven tomcat

我正在基于JSF和Hibernate的项目的生产部署中工作。该项目是使用Maven构建的。在Windows中的tomcat localhost servlet上运行它时,应用程序运行得很好,但是当我尝试在Ubuntu 16.04机器上部署它时(也使用tomcat),我得到了一些与hibernate相关的错误。 我知道我发布了很多代码,但我并不确切知道错误的位置。

这是来自Ubuntu服务器中catalina.out的tomcat错误日志。该日志位于/opt/tomcat/logs/catalina.out:

02-Oct-2017 11:25:55.859 INFO [http-nio-8080-exec-13] org.hibernate.cfg.Environment.<clinit> HHH000206: hibernate.properties not found
02-Oct-2017 11:25:55.861 INFO [http-nio-8080-exec-13] org.hibernate.cfg.Environment.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
Failed to create sessionFactory object.java.lang.NoSuchMethodError: org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(Ljava/util/LinkedHashSet;$
02-Oct-2017 11:25:56.120 ADVERTENCIA [http-nio-8080-exec-13] com.sun.faces.lifecycle.InvokeApplicationPhase.execute #{beanLogin.validateUsernamePassword}: j$
 javax.faces.FacesException: #{beanLogin.validateUsernamePassword}: java.lang.ExceptionInInitializerError
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
        at javax.faces.component.UICommand.broadcast(UICommand.java:315)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
        at resources.AuthorizationFilter.doFilter(AuthorizationFilter.java:39)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Caused by: javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
        ... 31 more
Caused by: java.lang.ExceptionInInitializerError
        at eLagun.HibernateUtil.buildSessionFactory(HibernateUtil.java:37)
        at eLagun.HibernateUtil.<clinit>(HibernateUtil.java:10)
        at eLagun.Dao.<clinit>(Dao.java:29)
        at beans.beanLogin.validateUsernamePassword(beanLogin.java:43)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
        ... 32 more
Caused by: java.lang.NoSuchMethodError: org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(Ljava/util/LinkedHashSet;Lorg/hibernate/service/class$
        at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:89)
        at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:66)
        at org.hibernate.service.ServiceRegistryBuilder.<init>(ServiceRegistryBuilder.java:76)
        at eLagun.HibernateUtil.buildSessionFactory(HibernateUtil.java:29)
        ... 43 more

java.lang.ExceptionInInitializerError

以下脚本片段是我认为问题所在的片段。

hibernate.cfg.xml中:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/elagun_1</property>
        <property name="connection.username">USER</property>
        <property name="connection.password">PASS</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">false</property>
        <property name="hbm2ddl.auto">validate</property>

        <mapping class="eLagun.Familiar" />
        <mapping class="eLagun.Paciente" />
        <mapping class="eLagun.Test" />
        <mapping class="eLagun.Pregunta" />
        <mapping class="eLagun.Resultado" />
        <mapping class="eLagun.Medico" />
        <mapping class="eLagun.Respuesta" />
        <mapping class="eLagun.Respuesta_pregunta" />

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

HibernateUtil类创建一个SessionFactory实例:

package eLagun;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();
    private static ServiceRegistryBuilder registry;
    private static ServiceRegistry serviceRegistry;

    private static SessionFactory buildSessionFactory() {

        try {
            Configuration configuration = new Configuration();
            configuration.configure();

            configuration.addAnnotatedClass(Paciente.class);
            configuration.addAnnotatedClass(Pregunta.class);
            configuration.addAnnotatedClass(Familiar.class);
            configuration.addAnnotatedClass(Test.class);
            configuration.addAnnotatedClass(Resultado.class);
            configuration.addAnnotatedClass(Medico.class);
            configuration.addAnnotatedClass(Respuesta.class);
            configuration.addAnnotatedClass(Respuesta_pregunta.class);

            registry = new ServiceRegistryBuilder();
            registry.applySettings(configuration.getProperties());
            serviceRegistry = registry.buildServiceRegistry();
            return configuration.buildSessionFactory(serviceRegistry);

        } catch (Throwable ex) {

            System.err.println("Failed to create sessionFactory object." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        System.out.println("entro en hibernate util get session factory");
        return sessionFactory;
    }

    public static void closeSessionFactory() {
        if ((sessionFactory != null) && (sessionFactory.isClosed() == false)) {
            sessionFactory.close();
        }
    }
}

最后,这是Dao方法autenticarMedico(),其中应用程序正在崩溃,因为日志错误显示。我注意到这适用于windows localhost。在使用Dao.autenticarMedico(用户,pwd)时,在关注以Medico登录时崩溃:

public static int autenticarMedico(String username, String password) {

        Query q = session.createQuery(
                "" + "from Medico " + "where userMedico =\'" + username + "\' AND password = \'" + password + "\'");

        if(q.list().size() <= 0)
            return -1;
        else {
            Medico medico = (Medico) q.list().get(0);
            return medico.getIdMedico();
        }
    }

这是pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>eLagun2</groupId>
    <artifactId>eLagun2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.7.SP1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jboss.logging</groupId>
                    <artifactId>jboss-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
    </dependencies>
</project>

这是项目结构,以显示正在使用的其他库和依赖项:

Project Structure

PS:我已经尝试将hibernate.cfg.xml移动到资源包,正如有些人在其他帖子中建议的那样,但它没有用。

0 个答案:

没有答案