在Websphere自由配置文件8.5.5上使用ejb无状态的CODI

时间:2013-10-31 14:28:13

标签: websphere-liberty codi

如果webapp包含@Stateless ejb,我无法启动在websphere liberty profile 8.5.5上嵌入CODI的webapp。

我得到了这个例外:

[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)。

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

当第一个HTTP请求由webapp处理时,FacesServlet被初始化并且CodiNavigationHandler被实例化。

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

此应用程序上下文已经创建(部署webapp时),但尚未调用LibertyContextsService.initApplicationContext(String)。 因此,LibertyContextsService.applicationContexts ThreadLocal变量上的应用程序上下文为空,并发生错误:

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

重现:

  • 创建动态Web项目
  • 在WEB-INF(仅beans元素)
  • 下添加几乎空的beans.xml
  • 在WEB-INF(仅faces-config元素)
  • 下添加几乎空的faces-config.xml
  • 添加带有faces / index.xhtml
  • 的web.xml
  • 在WEB-INF / lib(http://www.apache.org/dyn/closer.cgi/myfaces/binaries/myfaces-extcdi-assembly-jsf20-1.0.5-bin.zip
  • 中复制codi jar
  • 添加无状态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:

    import javax.inject.Inject;
    import javax.inject.Named;
    
    @Named
    public class MyController {
    
        @Inject
        private MyBean myBean;
    
        public String getTitle() {
            return myBean.getTitle();
        }
    }
    
  • 添加一个简单的jsf网页:

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

nota :如果删除ejb上的@stateless,则应用程序可以正常工作。

1 个答案:

答案 0 :(得分:1)

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

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

所以现在,我已经转向了jboss。