我关注的问题。出于某些原因,我在一个EAR内的两个不同的WAR模块中有一个jar的副本。不幸的是,通过CDI引入注入失败,因为类加载器检测到两个实现,并且它不知道应该使用哪个实现。有一个错误是这样的:
07:28:35,411 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 215) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./webadm: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./webadm: java.lang.RuntimeException: javax.servlet.ServletException: UT010013: Could not instantiate com.adminconsole.SessionObserver
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.RuntimeException: javax.servlet.ServletException: UT010013: Could not instantiate com.wincor.adminconsole.session.SessionObserver
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:231)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
... 6 more
Caused by: javax.servlet.ServletException: UT010013: Could not instantiate com.adminconsole.SessionObserver
at io.undertow.servlet.core.ManagedListener.start(ManagedListener.java:50)
at io.undertow.servlet.core.ApplicationListeners.start(ApplicationListeners.java:159)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:173)
... 8 more
Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:134)
at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)
at org.jboss.as.ee.component.ComponentRegistry$ComponentManagedReferenceFactory.getReference(ComponentRegistry.java:149)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$6.createInstance(UndertowDeploymentInfoService.java:1372)
at io.undertow.servlet.core.ManagedListener.start(ManagedListener.java:48)
... 10 more
Caused by: java.lang.IllegalArgumentException: Can not set com.adminconsole.jsf.context.OcmInitFacesContextFactory field com.adminconsole.SessionObserver.contextFactory to com.adminconsole.jsf.context.OcmInitFacesContextFactory$Proxy$_$$_WeldClientProxy
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:94)
at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:363)
at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:374)
at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:71)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:73)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
at org.jboss.as.weld.injection.WeldInjectionContext.inject(WeldInjectionContext.java:39)
at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:51)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
... 15 more
OcmInitFacesContextFactory通过@Inject注释注入SessionObserver
确定它是由重复引起的,因为如果没有复制的jar,它就能正常工作。
我的问题不在于,有没有办法告诉CDI(Weld)仅在一个WAR模块中搜索依赖项?我试图将它排除在扫描之外(在这个jar文件中的beans.xml中),但这不是重点,因为它根本不会注入它们。目前我无法更改此EAR和WAR文件的设计。