1

我用JSF2.0写了一个动态web项目,可以在Glassfish 3.0.1中成功部署。现在我想把它移到Tomcat 7。但是我在部署过程中遇到了以下异常:

javax.servlet.ServletException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)

根本原因

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:679)
org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:709)
org.jboss.weld.bean.AbstractReceiverBean.getReceiver(AbstractReceiverBean.java:83)
org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:140)
org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:360)
org.jboss.weld.context.AbstractMapContext.get(AbstractMapContext.java:112)
org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:143)
org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:100)
org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
javax.servlet.http.HttpSession_$$_javassist_4.getId(HttpSession_$$_javassist_4.java)
org.jboss.weld.servlet.HttpPassThruSessionBeanStore.loadFromSession(HttpPassThruSessionBeanStore.java:120)
org.jboss.weld.servlet.HttpPassThruSessionBeanStore.attachToSession(HttpPassThruSessionBeanStore.java:68)
org.jboss.weld.servlet.ConversationBeanStore.<init>(ConversationBeanStore.java:41)
org.jboss.weld.conversation.ServletConversationManager.getBeanStore(ServletConversationManager.java:56)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)
org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:113)
org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
org.jboss.weld.conversation.ServletConversationManager_$$_javassist_0.getBeanStore(ServletConversationManager_$$_javassist_0.java)
org.jboss.weld.jsf.WeldPhaseListener.initiateSessionAndConversation(WeldPhaseListener.java:178)
org.jboss.weld.jsf.WeldPhaseListener.beforeRestoreView(WeldPhaseListener.java:118)
org.jboss.weld.jsf.WeldPhaseListener.beforePhase(WeldPhaseListener.java:87)
com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

我不明白为什么会这样。我没有在我的代码中使用任何RequestScoped 。这是我的 Tomcat 的 lib jar:

    annotations-api.jar
    catalina-ant.jar
    catalina-ha.jar
    catalina-tribes.jar
    catalina.jar
    ecj-3.6.2.jar
    ecj-4.2.2.jar
    el-api-2.2.jar
    el-impl-2.2.jar
    jasper-el.jar
    jasper.jar
    jsf-api-2.0.jar
    jsf-impl-2.0.6.jar
    jsp-api.jar
    jstl-1.1.2.jar
    ojdbc14.jar
    servlet-api.jar
    standard.jar
    tomcat-api.jar
    tomcat-coyote.jar
    tomcat-dbcp.jar
    tomcat-i18n-es.jar
    tomcat-i18n-fr.jar
    tomcat-i18n-ja.jar
    tomcat-jdbc.jar
    tomcat-util.jar
    weld-servlet-1.0.1-Final.jar

而我的 JSF 项目的 web.xml 是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>bighunter</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>casablanca</param-value>
  </context-param>
  <listener>
    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>   
  </listener>
</web-app>

有人可以帮我吗?我被这个问题困扰了好几天。非常感谢!

4

0 回答 0