在 Websphere 自由配置文件 8.5.5 上使用 ejb 无状态的 CODI [英] CODI with ejb stateless on Websphere liberty profile 8.5.5

查看:29
本文介绍了在 Websphere 自由配置文件 8.5.5 上使用 ejb 无状态的 CODI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 Web 应用程序包含 @Stateless ejb,我将无法启动在 WebSphere 自由配置文件 8.5.5 上嵌入 CODI 的 Web 应用程序.

I cannot launch a webapp that embedd CODI on websphere liberty profile 8.5.5 if the webapp contains a @Stateless ejb.

我收到此异常:

[ERROR   ] null
java.lang.reflect.InvocationTargetException
[ERROR   ] An error occured while initializing MyFaces: java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
[ERROR   ] Uncaught.init.exception.thrown.by.servlet 
    Faces Servlet
    codiTest
    javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @ApplicationScoped does not exist within current thread
    at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:342)
    at [internal classes]
    at org.apache.myfaces.extensions.cdi.core.api.config.CodiCoreConfig_$$_javassist_78.isAdvancedQualifierRequiredForDependencyInjection(CodiCoreConfig_$$_javassist_78.java)
    at org.apache.myfaces.extensions.cdi.jsf.impl.listener.phase.PhaseListenerExtension.consumePhaseListeners(PhaseListenerExtension.java:110)
    at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleFactoryWrapper.getLifecycle(CodiLifecycleFactoryWrapper.java:67)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:119)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:322)
    at [internal classes]

[ERROR   ] SRVE0266E: Error occured while initializing servlets: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:385)
    at [internal classes]
Caused by: javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @ApplicationScoped does not exist within current thread
    at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:342)
    at [internal classes]
    at org.apache.myfaces.extensions.cdi.core.api.config.CodiCoreConfig_$$_javassist_78.isAdvancedQualifierRequiredForDependencyInjection(CodiCoreConfig_$$_javassist_78.java)
    at org.apache.myfaces.extensions.cdi.jsf.impl.listener.phase.PhaseListenerExtension.consumePhaseListeners(PhaseListenerExtension.java:110)
    at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleFactoryWrapper.getLifecycle(CodiLifecycleFactoryWrapper.java:67)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:119)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:322)
    ... 1 more

[WARNING ] Unknown RenderKit 'HTML_BASIC'.
[WARNING ] Unknown RenderKit 'HTML_BASIC'.
[ERROR   ] An exception occurred
java.lang.IllegalArgumentException: Could not find a RenderKit for "HTML_BASIC"

我认为只有在项目中存在 ejb 时才会出现问题(在我的例子中是 @Stateless ejb).

I've constated that the problem occurs only if an ejb is present in the project (in my case a @Stateless ejb).

在这种情况下,应用程序上下文在服务器启动和 web 应用程序安装/部署时初始化.这里没问题.

In this case, the application context is initialized when the server is started and the webapp installed/deployed. No problem here.

当第一个 HTTP 请求由 web 应用程序处理时,FacesServlet 被初始化并且 CodiNavigationHandler 被实例化.

When the first HTTP request is handled by the webapp, the FacesServlet is initialized and CodiNavigationHandler is instanciated.

方法 CodiNavigationHandler.isAddViewConfigsAsNavigationCaseActivated() 在构造函数中被调用,并尝试获取对 CODI JsfModuleConfig 的引用.这个 JsfModuleConfig 有一个 @ApplicationScoped 注释,beanManager 尝试获取应用程序上下文.

The method CodiNavigationHandler.isAddViewConfigsAsNavigationCaseActivated() is called in the constructor and tries to get a reference on CODI JsfModuleConfig. This JsfModuleConfig has an @ApplicationScoped annotation and the the beanManager tries to get the application context.

此应用程序上下文已创建(在部署 web 应用程序时),但尚未调用 LibertyContextsService.initApplicationContext(String).所以应用程序上下文在 LibertyContextsService.applicationContexts ThreadLocal 变量上为空,并且发生错误:

This application context has already been created (when the webapp is deployed) but the LibertyContextsService.initApplicationContext(String)has not been called yet. So the application context is null on the LibertyContextsService.applicationContexts ThreadLocal variable and the error occurs:

WebBeans context with scope type annotation @ApplicationScoped does not exist within current thread

重现:

  • create a Dynamic Web Project
  • add an almost empty beans.xml under WEB-INF (just a beans element)
  • add an almost empty faces-config.xml under WEB-INF (just a faces-config element)
  • add a web.xml with a faces/index.xhtml
  • copy codi jars in WEB-INF/lib (http://www.apache.org/dyn/closer.cgi/myfaces/binaries/myfaces-extcdi-assembly-jsf20-1.0.5-bin.zip)
  • add a stateless bean:

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;

@Stateless
public class MyBean {

    @PostConstruct
    public void postConstruct() {
        System.out.println("post construct: " + this);
    }

    public String getTitle() {
        return "test";
    }
}

  • 添加一个jsf bean:

  • add a jsf bean:

    import javax.inject.Inject;
    import javax.inject.Named;
    
    @Named
    public class MyController {
    
        @Inject
        private MyBean myBean;
    
        public String getTitle() {
            return myBean.getTitle();
        }
    }
    

  • 添加一个简单的 jsf 网页:

  • add a simple jsf web page with:

    <h:body>
        <h:outputText>${myController.title}</h:outputText>
    </h:body>
    

  • 注意:如果删除 ejb 上的 @stateless,应用程序将正常工作.

    nota: if you remove the @stateless on the ejb, the application works.

    推荐答案

    实际上它似乎是一个错误(我也在 IBM 论坛上发布了这个问题:https://www.ibmworks/commun.com/forums/html/topic?id=f372bbc5-5ba4-4c2a-9ef0-0bdcd76766da#09228314-2baf-4892-899e-5a8cc52daa19).

    Effectively it seems to be a bug (I also post the question on IBM forums: https://www.ibm.com/developerworks/community/forums/html/topic?id=f372bbc5-5ba4-4c2a-9ef0-0bdcd76766da#09228314-2baf-4892-899e-5a8cc52daa19).

    我将尝试找到一种方法来创建 PMR(我在一家大公司,很难找到合适的人来授予我访问权限).

    I'm going to try to find a way to create a PMR (I'm in a big company, difficult to find the right person that will grant me access to that).

    所以现在,我已经切换到 jboss.

    So for now, I've switched to jboss.

    这篇关于在 Websphere 自由配置文件 8.5.5 上使用 ejb 无状态的 CODI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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