5

JBoss 7.1、OmniFaces 1.6、Eclipse 开普勒、CDI 1.0

当我从 OmniFaces 1.5 更新到 OmniFaces 1.6 时,我发现新的 Omnifaces 1.6 出现以下情况。我想这与 OmniFaces 1.6 的新的有趣的 CDI 功能有关。

我在一个 EAR 存档中有两个基于 JSF 的 WAR 项目,这两个项目都具有 OmniFaces 作为依赖项,并且它们都将被部署。在部署中,OmniFaces 1.6 最终出现在/WEB-INF/lib两个 WAR 项目中。在 JBoss 开始时,IllegalArgumentException抛出了。

java.lang.IllegalArgumentException: Registering converter 'class org.omnifaces.converter.ListConverter' failed, duplicates converter ID 'omnifaces.ListConverter' of other converter 'class org.omnifaces.converter.ListConverter'.
    at org.omnifaces.cdi.converter.ConverterExtension.processConverters(ConverterExtension.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
    at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
    at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
    at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
    at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241)
    at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229)
    at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207)
    at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:569)
    at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:559)
    at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:60)
    at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:38)
    at org.jboss.weld.bootstrap.events.ProcessManagedBeanImpl.fire(ProcessManagedBeanImpl.java:30)
    at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:123)
    at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:204)
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:344)
    at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82)
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)

如果我删除一个 WAR 项目,那么异常就会消失,我可以在 EAR 中使用另一个 WAR 项目。

是否可以在多个项目中使用 OmniFaces 1.6,并在一个 EAR 中部署到 JBoss 7.1.1?

4

1 回答 1

3

This bug has been fixed in 1.6.1. There's quite a story behind this bug, so I just wrote a blog on that: CDI behaved unexpectedly in EAR, so OmniFaces 1.6.1 released!

Summarized: CDI context isn't WAR-wide, but EAR-wide. As to the particular exception you faced, it's because there was only one CDI ConverterExtension being loaded from one WAR which is then applied EAR-wide and thus processing all @FacesConverter classes from both WARs instead of the WAR where the CDI extension was being loaded from.

Note that this is not a problem in OmniFaces. This is a problem in the way how CDI works in EARs.


Update: as per issue WELD-2143 this peculiar problem has finally been fixed in Weld 2.3.5. I have tested it in a patched WildFly 10.0.0 and confirmed that all OmniFaces CDI features which depend on an Extension, the @ViewScoped, @Eager and @Param work again in both WARs in a single EAR.

So, if you struggle with using aforementioned OmniFaces CDI features in an EAR with multiple WARs, make sure you upgrade Weld to at least version 2.3.5. The problem remains open in OpenWebBeans.

于 2013-10-07T19:38:30.213 回答