为啥在 JBoss7.1.EAP 中运行应用程序时出现 java.lang.NoSuchMethodError

Posted

技术标签:

【中文标题】为啥在 JBoss7.1.EAP 中运行应用程序时出现 java.lang.NoSuchMethodError【英文标题】:Why am I getting java.lang.NoSuchMethodError while running application in JBoss7.1.EAP为什么在 JBoss7.1.EAP 中运行应用程序时出现 java.lang.NoSuchMethodError 【发布时间】:2019-05-15 19:29:58 【问题描述】:

我在使用 Hibernate5.2.17.Final 在 JBoss7.1.EAP 和 Spring5.0.0.RELEASE 中运行应用程序时遇到此错误。代码编译正常。但是当我运行应用程序时它失败了。失败的代码是:

public List loadTransformedObjectWithNativeSQL(String paramString, Map paramMap, Object[] paramArrayOfObject, Class paramClass)
  
    Object localObject = null;
    NativeQuery localNativeQuery = this.sessionFactory.getCurrentSession().createNativeQuery(paramString);
    Iterator localIterator = paramMap.entrySet().iterator();
    while (localIterator.hasNext())
    
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      String str = (String)localEntry.getKey();
      Type localType = (Type)localEntry.getValue();
      localNativeQuery.addScalar(str, localType);
    
    for (int i = 1; i <= paramArrayOfObject.length; i++) 
        localNativeQuery.setParameter(i, paramArrayOfObject[(i - 1)]);
      
    localNativeQuery.setResultTransformer(Transformers.aliasToBean(paramClass));
    return localNativeQuery.list();
  

我还尝试阻止不支持 Jboss-deployment-descriptor.xml 中的 Nativequery 的 Jboss 的休眠 jar.. 但没有用

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.apache.commons.logging" />
        </exclusions>
        <exclude-subsystems>
            <subsystem name="org.hibernate" />
            <subsystem name="org.hibernate.validator" />
        </exclude-subsystems>
        <exclusions>
            <module name="org.hibernate" />
            <module name="org.hibernate.validator" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

错误如下,请检查。

14:04:59,308 INFO  [com.gee.gecs.cosmos.dao.ServiceDaoImpl] (default task-3) ***************select cud.user_id validUser from cost_user cud where sso_id = ? and cud.rec_status_ind = '1'
    14:04:59,308 INFO  [com.gee.gecs.cosmos.dao.ServiceDaoImpl] (default task-3) ###############validUser=org.hibernate.type.StringType@68d657ce
    14:04:59,342 ERROR [com.gee.gecs.cosmos.aspect.ICAMExceptionHandler] (default task-3) A NestedServletException has occured in the application: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.Session.createNativeQuery(Ljava/lang/String;)Lorg/hibernate/query/NativeQuery;
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1006)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
        at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
        at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
        at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
        at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
        at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
        at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
        at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
        at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.NoSuchMethodError: org.hibernate.Session.createNativeQuery(Ljava/lang/String;)Lorg/hibernate/query/NativeQuery;
        at com.gee.gecs.cosmos.dao.BaseDao.loadTransformedObjectWithNativeSQL(BaseDao.java:211)
        at com.gee.gecs.cosmos.dao.ServiceDaoImpl.getUserValidation(ServiceDaoImpl.java:450)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

上面给出了异常堆栈跟踪。

【问题讨论】:

【参考方案1】:

我能够通过将 hibernate5.2.17Final jar 放在 or.hiberante.main 文件夹中替换旧 jar 并更改 module.xml 中的引用来解决问题

【讨论】:

以上是关于为啥在 JBoss7.1.EAP 中运行应用程序时出现 java.lang.NoSuchMethodError的主要内容,如果未能解决你的问题,请参考以下文章

为啥在 gunicorn 上运行的烧瓶应用程序中使用日志轮换时同时在多个文件上写入日志?

为啥 Firebase 在 Android 模拟器上运行时在 PhoneGap 应用程序中返回 404 错误?

为啥我的系统映像在运行时没有显示在我的应用程序中? [复制]

为啥我的 Cardview 在我运行时没有出现在布局中

在 Eclipse 中使用 aar - 为啥第 3 方活动在构建时解决而不是运行时解决?

为啥运行应用程序时 Eclipse CPU 使用率会增加?