Jetty Maven插件(jetty:运行目标)+ Weld CDI + JSF 2.2 = ViewScoped bean上的NPE [英] Jetty Maven plugin (jetty:run goal) + Weld CDI + JSF 2.2 = NPE on ViewScoped beans

查看:109
本文介绍了Jetty Maven插件(jetty:运行目标)+ Weld CDI + JSF 2.2 = ViewScoped bean上的NPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Web应用程序中使用以下(最新的)组件:

Using the following (pretty up to date) components in the web application:

Jetty Maven插件9.2.6.v20141205

Jetty maven plugin 9.2.6.v20141205

焊接CDI 2.2.9.最终

Weld CDI 2.2.9.Final

Mojarra JSF 2.2.10

Mojarra JSF 2.2.10

应用程序的web.xml包含以下侦听器:

The app's web.xml contains the following listeners:

org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener
com.sun.faces.config.ConfigureListener

第一个侦听器向JNDI注册BeanManager. 第二个侦听器初始化JSF并在JNDI中查找BeanManager.

The first listener registers BeanManager with JNDI. The second listener initializes JSF and looks up for BeanManager in the JNDI.

当Jetty Maven插件以"jetty:run-war"目标运行时,或者当应用程序独立运行并嵌入嵌入式jetty时,此设置都可以正常运行.

This setup works perfectly ok when jetty maven plugin runs with "jetty:run-war" goal or when the application is running as standalone with embedded jetty.

但是,当以"jetty:run"目标运行它时,在第一个侦听器中注册的BeanManager在JSF中不可见,从而导致ViewScoped Bean上出现NPE.

However when running it with "jetty:run" goal the BeanManager registered in the first listener is not visible in the JSF resulting in NPE's on the ViewScoped beans.

在我看来,这似乎是范围或可见性问题,但我无法弄清楚-jetty:run和jetty:run-war有什么区别.

This seems to me like a scope or visibility issue but I can't figure that out - what is the difference between jetty:run and jetty:run-war.

我尝试在web.xml中添加"resource-env-ref"条目,并在各种Jetty的xml文件(jetty.xml,jetty-env.xml,jetty-context.xml)中创建BeanManager,但是没有这样做.不能改变任何东西.

I have tried adding "resource-env-ref" entries in the web.xml and creating the BeanManager in various Jetty's xml files (jetty.xml, jetty-env.xml, jetty-context.xml) but it didn't change anything.

更新:

NPE在会话无效时发生;因为在JSF中没有注册BeanManager,所以不能销毁ViewScoped bean.请参见下面的堆栈跟踪:

NPE occurs upon session invalidation; as there is no BeanManager registered in the JSF the ViewScoped beans cannot be destroyed. See below stack trace:

由以下原因引起:java.lang.NullPointerException com.sun.faces.application.view.ViewScopeContextManager.destroyBeans(ViewScopeContextManager.java:171) 在 com.sun.faces.application.view.ViewScopeContextManager.sessionDestroyed(ViewScopeContextManager.java:339) 在 com.sun.faces.application.view.ViewScopeManager.sessionDestroyed(ViewScopeManager.java:369) 在 com.sun.faces.application.WebappLifecycleListener.sessionDestroyed(WebappLifecycleListener.java:181) 在 com.sun.faces.config.ConfigureListener.sessionDestroyed(ConfigureListener.java:399) 在 org.eclipse.jetty.server.session.AbstractSessionManager.removeSession(AbstractSessionManager.java:772) 在 org.eclipse.jetty.server.session.AbstractSession.invalidate(AbstractSession.java:326) 在 com.sun.faces.context.ExternalContextImpl.invalidateSession(ExternalContextImpl.java:783)

Caused by: java.lang.NullPointerException at com.sun.faces.application.view.ViewScopeContextManager.destroyBeans(ViewScopeContextManager.java:171) at com.sun.faces.application.view.ViewScopeContextManager.sessionDestroyed(ViewScopeContextManager.java:339) at com.sun.faces.application.view.ViewScopeManager.sessionDestroyed(ViewScopeManager.java:369) at com.sun.faces.application.WebappLifecycleListener.sessionDestroyed(WebappLifecycleListener.java:181) at com.sun.faces.config.ConfigureListener.sessionDestroyed(ConfigureListener.java:399) at org.eclipse.jetty.server.session.AbstractSessionManager.removeSession(AbstractSessionManager.java:772) at org.eclipse.jetty.server.session.AbstractSession.invalidate(AbstractSession.java:326) at com.sun.faces.context.ExternalContextImpl.invalidateSession(ExternalContextImpl.java:783)

推荐答案

Dimitri在码头项目上提出了一个错误:

Dimitri raised a bug on the jetty project: https://bugs.eclipse.org/bugs/show_bug.cgi?id=462179

该错误包含问题原因的完整描述.简而言之,Weld使BeanManager可用于JSF的方式不适用于未组装的Web应用程序(对于mvn jetty:run就是这种情况),只有war文件(即mvn jetty:run-war将起作用).

The bug contains a full description of the cause of the problem. In short, the way Weld makes the BeanManager available to JSF does not work with unassembled webapps (which is the case with mvn jetty:run), only war files (ie mvn jetty:run-war will work).

Jan

这篇关于Jetty Maven插件(jetty:运行目标)+ Weld CDI + JSF 2.2 = ViewScoped bean上的NPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆