java.lang.NoSuchMethodError: org/omnifaces/util/Beans.getAnnotation

java.lang.NoSuchMethodError: org/omnifaces/util/Beans.getAnnotation

我已尝试将我的 Omnifaces 库从 1.7 更新到 1.8.3,但我的应用程序无法启动并出现以下堆栈跟踪错误:

[1/7/16 12:28:05:909 IST] 0000001e BeansDeployer E BeansDeployer deploy 
                                 javax.enterprise.event.ObserverException: Caught Exception while handling event object with type : org.apache.webbeans.portable.events.generics.GProcessManagedBean
    at org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:469)
    at org.apache.webbeans.container.BeanManagerImpl.fireEvent(BeanManagerImpl.java:454)
    at org.apache.webbeans.util.WebBeansUtil.defineManagedBean(WebBeansUtil.java:3203)
    at org.apache.webbeans.config.BeansDeployer.defineManagedBean(BeansDeployer.java:894)
    at org.apache.webbeans.config.BeansDeployer.deploySingleAnnotatedType(BeansDeployer.java:542)
    at org.apache.webbeans.config.BeansDeployer.deployFromClassPath(BeansDeployer.java:488)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:171)
    at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:124)
    at org.apache.webbeans.web.lifecycle.WebContainerLifecycle.startApplication(WebContainerLifecycle.java:77)
    at com.ibm.ws.webbeans.common.CommonLifeCycle.startApplication(CommonLifeCycle.java:106)
    at com.ibm.ws.webbeans.services.JCDIServletContainerInitializer.onStartup(JCDIServletContainerInitializer.java:85)
    at com.ibm.ws.webcontainer.webapp.WebAppImpl.initializeServletContainerInitializers(WebAppImpl.java:609)
    at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:405)
    at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
    at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169)
    at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:749)
    at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:634)
    at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:422)
    at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:714)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1167)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1370)
    at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:639)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:773)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1369)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2170)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:435)
    at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:378)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access0(CompositionUnitMgrImpl.java:126)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.run(CompositionUnitMgrImpl.java:653)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5471)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5597)
    at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:667)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:611)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1259)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:69)
    at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:272)
    at javax.management.modelmbean.RequiredModelMBean.run(RequiredModelMBean.java:1152)
    at java.security.AccessController.doPrivileged(AccessController.java:388)
    at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30)
    at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:41)
    at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1146)
    at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:999)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:847)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:783)
    at com.ibm.ws.management.AdminServiceImpl.run(AdminServiceImpl.java:1350)
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
    at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1243)
    at com.ibm.ws.management.remote.AdminServiceForwarder.invoke(AdminServiceForwarder.java:346)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
    at javax.management.remote.rmi.RMIConnectionImpl.access0(RMIConnectionImpl.java:86)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:830)
    at javax.management.remote.rmi._RMIConnectionImpl_Tie.invoke(_RMIConnectionImpl_Tie.java:751)
    at javax.management.remote.rmi._RMIConnectionImpl_Tie._invoke(_RMIConnectionImpl_Tie.java:158)
    at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:631)
    at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:501)
    at com.ibm.rmi.iiop.ORB.process(ORB.java:623)
    at com.ibm.CORBA.iiop.ORB.process(ORB.java:1581)
    at com.ibm.rmi.iiop.Connection.doRequestWork(Connection.java:3151)
    at com.ibm.rmi.iiop.Connection.doWork(Connection.java:3016)
    at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
    at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1720)
Caused by: org.apache.webbeans.exception.WebBeansException: java.lang.reflect.InvocationTargetException
    at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:291)
    at org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:455)
    ... 73 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:285)
    ... 74 more
Caused by: java.lang.NoSuchMethodError: org/omnifaces/util/Beans.getAnnotation(Ljavax/enterprise/inject/spi/BeanManager;Ljavax/enterprise/inject/spi/Annotated;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
    at org.omnifaces.cdi.eager.EagerExtension.collect(EagerExtension.java:80)
    ... 79 more

[1/7/16 12:28:05:915 IST] 0000001e webapp        E com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0015E: Failure to initialize Web application MY_APP_VIEW

使用 Omnifaces 1.7 可以正常工作。

我的配置是:

java.lang.NoSuchMethodError: org/omnifaces/util/Beans.getAnnotation(Ljavax/enterprise/inject/spi/BeanManager;Ljavax/enterprise/inject/spi/Annotated;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;

此方法在 OmniFaces 1.8 中 introduced。因此,此异常表明在 webapp 的运行时类路径中的某处仍然存在重复的和旧版本的 OmniFaces 库。

去掉它,这个问题就会消失。