首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenWebBeans + MyFaces + Tomcat = IllegalStateException

OpenWebBeans + MyFaces + Tomcat = IllegalStateException
EN

Stack Overflow用户
提问于 2016-05-09 21:46:09
回答 2查看 1.3K关注 0票数 0

我正在尝试让OWB (使用MyFaces & Primefaces)开发Tomcat8.0.33。不管我怎么配置东西,我都会出错.

代码语言:javascript
复制
org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: It's not allowed to call getBeans(Type, Annotation...) before AfterBeanDiscovery

此堆栈跟踪的...followed:

代码语言:javascript
复制
java.lang.IllegalStateException: It's not allowed to call getBeans(Type, Annotation...) before AfterBeanDiscovery
    at org.apache.webbeans.container.InjectableBeanManager.checkAfterBeanDiscoveryProcessed(InjectableBeanManager.java:402)
    at org.apache.webbeans.container.InjectableBeanManager.getBeans(InjectableBeanManager.java:121)
    at org.apache.myfaces.cdi.util.CDIUtils.lookup(CDIUtils.java:45)
    at org.apache.myfaces.flow.cdi.DefaultCDIFacesFlowProvider.getAnnotatedFlows(DefaultCDIFacesFlowProvider.java:51)
    at org.apache.myfaces.flow.impl.AnnotatedFlowConfigurator.configureAnnotatedFlows(AnnotatedFlowConfigurator.java:42)
    at org.apache.myfaces.config.FacesConfigurator.configureFlowHandler(FacesConfigurator.java:1666)
    at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:608)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:416)
    at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:73)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:172)
    at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:121)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4809)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5251)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1696)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:484)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:433)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1471)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1312)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1404)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:832)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    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)

基于我所读到的这里这里这里 (以及其他五个地方),我尝试了Tomcat插件依赖项,使用了web.xml中指定的OWB监听器,甚至这两个监听器。看起来,无论我做什么,我似乎都无法说服OWB在MyFaces跳进并开始做它的事情之前去做它的事情。我是不是漏掉了一些特别明显的东西?

代码语言:javascript
复制
// Maven Dependencies
com.amazonaws:aws-java-sdk-dynamodb:1.10.72

org.apache.myfaces.core:myfaces-api:2.2.10
org.apache.myfaces.core:myfaces-impl:2.2.10

org.apache.openwebbeans:openwebbeans-spi:1.6.3
org.apache.openwebbeans:openwebbeans-impl:1.6.3
org.apache.openwebbeans:openwebbeans-web:1.6.3
org.apache.openwebbeans:openwebbeans-jsf:1.6.3
org.apache.openwebbeans:openwebbeans-el22:1.6.3
org.apache.openwebbeans:openwebbeans-tomcat7:1.6.3

org.apache.geronimo.specs:geronimo-atinject_1.0_spec:1.0
org.apache.geronimo.specs:geronimo-jcdi_1.1_spec:1.0
org.apache.geronimo.specs:geronimo-interceptor_1.2_spec:1.0
org.apache.geronimo.specs:geronimo-annotation_1.2_spec:1.0

javax.enterprise:cdi-api:1.2
javax.validation:validation-api:1.1.0.Final
org.hibernate:hibernate-validator:5.2.4.Final

org.primefaces:primefaces:5.3
org.primefaces.themes:dark-hive:1.0.10

com.google.guava:guava:19.0
com.google.code.gson:gson:2.5

org.jetbrains:annotations:15.0
EN

回答 2

Stack Overflow用户

发布于 2016-11-06 10:19:02

你应该使用ContextLifecycleListener.java

将addOwbListeners()方法更改为下面

代码语言:javascript
复制
private void addOwbListeners(StandardContext context) {
  String[] oldListeners = context.findApplicationListeners();
  LinkedList<String> listeners = new LinkedList<String>();

  // 3rd
  listeners.addFirst("org.apache.myfaces.webapp.StartupServletContextListener");
  // 2nd
  listeners.addFirst("org.apache.webbeans.web.tomcat7.ContextLifecycleListener");
  // 1st
  listeners.addFirst("org.apache.webbeans.servlet.WebBeansConfigurationListener");

  for (String listener : oldListeners) {
    listeners.add(listener);
    context.removeApplicationListener(listener);
  }

  for (String listener : listeners) {
    context.addApplicationListener(listener);
  }
}

这个类加载在tomcat的普通类加载器中。不是webapp上下文类加载器。https://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html

/META/context.xml

代码语言:javascript
复制
<Context>
  <Listener className="mypackage.ContextLifecycleListener" />
  <Resource name="BeanManager" auth="Container"
    type="javax.enterprise.inject.spi.BeanManager"
    factory="org.apache.webbeans.container.ManagerObjectFactory" />
</Context>

/web.xml/web.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<web-app
  xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1" metadata-complete="false"
>
<servlet>
  <servlet-name>facesServlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>facesServlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<resource-ref>
  <res-ref-name>BeanManager</res-ref-name>
  <res-type>javax.enterprise.inject.spi.BeanManager</res-type>
  <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
票数 0
EN

Stack Overflow用户

发布于 2018-10-24 12:36:56

这些产品的最新版本也有同样的问题:Tomcat9.0.12、MyFaces 2.3.2和OpenWebBeans 2.0.7。

根据OpenWebBeans 将OpenWebBeans添加到Servlet容器项目中的文档,我将配置侦听器添加到web.xml

代码语言:javascript
复制
<listener>
    <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
</listener>

这个解决了问题。

但是,请注意,根据添加Tomcat7插件的文档,问题也应该得到解决,但没有。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37125988

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档