OpenWebBeans CDI failing in Java 11

2019-07-11 05:31发布

问题:

My application is using Java 11, Tomcat 9.0.13 and OpenWeBeans CDI 2.0.8. While starting my Tomcat server I get the following error:

Dec 19, 2018 9:59:04 AM org.apache.webbeans.servlet.WebBeansConfigurationListener contextInitialized
SEVERE: An error occurred while starting application context path : [/abcServer]
Dec 19, 2018 9:59:04 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.apache.webbeans.servlet.WebBeansConfigurationListener
org.apache.webbeans.exception.WebBeansDeploymentException: java.lang.IllegalArgumentException
    at org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery.scan(AbstractMetaDataDiscovery.java:144)
    at org.apache.webbeans.lifecycle.AbstractLifeCycle.bootstrapApplication(AbstractLifeCycle.java:132)
    at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:104)
    at org.apache.webbeans.web.lifecycle.WebContainerLifecycle.startApplication(WebContainerLifecycle.java:87)
    at org.apache.webbeans.servlet.WebBeansConfigurationListener.contextInitialized(WebBeansConfigurationListener.java:85)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5110)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5633)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1694)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1684)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalArgumentException
    at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
    at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
    at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
    at org.apache.xbean.finder.AnnotationFinder.readClassDef(AnnotationFinder.java:1169)
    at org.apache.xbean.finder.AnnotationFinder.<init>(AnnotationFinder.java:147)
    at org.apache.xbean.finder.AnnotationFinder.<init>(AnnotationFinder.java:160)
    at org.apache.webbeans.corespi.scanner.xbean.OwbAnnotationFinder.<init>(OwbAnnotationFinder.java:37)
    at org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery.initFinder(AbstractMetaDataDiscovery.java:107)
    at org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery.scan(AbstractMetaDataDiscovery.java:140)
    ... 13 more

Dec 19, 2018 9:59:04 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.xyz.abc.application.impl.ApplicationControllerAdapter
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [com.xyz.abc.cleanup.CleanupJobController] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  cleanupJobController, Bean Owner : [null]
    at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:65)
    at org.apache.webbeans.container.InjectionResolver.getInjectionPointBean(InjectionResolver.java:271)
    at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:82)
    at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:65)
    at org.apache.webbeans.portable.InjectionTargetImpl.injectFields(InjectionTargetImpl.java:220)
    at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:206)
    at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:196)
    at com.xyz.abc.inject.CDIUtils.injectFields(CDIUtils.java:37)
    at com.xyz.abc.application.impl.ApplicationStarted.<init>(ApplicationStarted.java:149)
    at com.xyz.abc.application.impl.ApplicationControllerAdapter.contextInitialized(ApplicationControllerAdapter.java:34)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5110)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5633)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1694)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1684)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

Dec 19, 2018 9:59:04 AM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
INFO: WSSERVLET12: JAX-WS context listener initializing
Dec 19, 2018 9:59:04 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Dec 19, 2018 9:59:04 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/abcServer] startup failed due to previous errors
Dec 19, 2018 9:59:04 AM com.sun.xml.ws.transport.http.servlet.WSServletDelegate destroy
INFO: WSSERVLET15: JAX-WS servlet destroyed
Dec 19, 2018 9:59:04 AM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextDestroyed
INFO: WSSERVLET13: JAX-WS context listener destroyed
Dec 19, 2018 9:59:04 AM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class com.xyz.abc.application.impl.ApplicationControllerAdapter
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [com.xyz.abc.licensing.License] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  license, Bean Owner : [null]
    at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:65)
    at org.apache.webbeans.container.InjectionResolver.getInjectionPointBean(InjectionResolver.java:271)
    at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:82)
    at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:65)
    at org.apache.webbeans.portable.InjectionTargetImpl.injectFields(InjectionTargetImpl.java:220)
    at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:206)
    at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:196)
    at com.xyz.abc.inject.CDIUtils.injectFields(CDIUtils.java:37)
    at com.xyz.abc.application.impl.ApplicationStopped.<init>(ApplicationStopped.java:85)
    at com.xyz.abc.application.impl.ApplicationControllerAdapter.contextDestroyed(ApplicationControllerAdapter.java:27)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5157)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5830)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:221)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:149)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1694)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1684)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

Please suggest how to resolve this issue. I have updated the opewebbeans CDI for Tomcat to the latest one, updated JaxB-api as well but nothing seems to work. Is there anyone who is using Tomcat 9 with Java 11 ?

回答1:

TL;DR: You updated OWB from 1.6 to 2.0 but failed to update their dependencies.

OpenWebBeans 2.0.8 depends on xbean-asm7-shaded-4.12 which implementes the class org.apache.xbean.asm7.ClassReader. Somehow your OWB use an older class org.apache.xbean.asm5.ClassReader to discover CDI annotated bean classes. But developers in 2015 failed to predict how to read Java 11 classes in 2018 (scnr).

Testing a bit I found you must also have an old xbean-finder-shaded-4.3 in your classpath which depends on and uses that old org.apache.xbean.asm5.ClassReader from xbean-asm5-shaded.

As a conclusion I'd suggest you get rid of those dependency conflicts pointed out by your exception stack trace. Additionally you may want to use a build tool like maven. This helps a lot getting through the depdendency hell mostly without getting burned.

Edit:

Regarding your comment see these questions:

  • What dependency is missing when I get java.lang.NoClassDefFoundError: javax/ws/rs/client/RxInvokerProvider error?
  • jersey multiparty returns NoClassDefFoundError: org/glassfish/jersey/internal/inject/ExtractorException

Depending on your environment you may also need to add replacements for modules that have been deprecated in Java 9 and removed in Java 11:

  • Replacements for deprecated JPMS modules with Java EE APIs

Edit 2:

You can @Inject DocumentBuilderFactory instances using a producer method annotated with @Produces as descripbed in my answer to your followup question.