2011-06-22 71 views
2

對於我的應用我使用Tomcat的對6.0.x鑽嘴魚科1.2_04 JSF實現。 它工作正常,只是我想現在切換到MyFaces 1.2_10 JSF的impl。應用程序錯誤與MyFaces的1.2:java.lang.IllegalStateException:沒有工廠配置此應用

我的應用程序的部署期間收到以下錯誤:

ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myApp]] StandardWrapper.Throwable 
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions! 
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml. 
A typical config looks like this; 
<listener> 
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
</listener> 

    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:106) 
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:137) 
    at org.apache.myfaces.webapp.MyFacesServlet.init(MyFacesServlet.java:113) 
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172) 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992) 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058) 
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371) 
... 

這裏是我的web.xml配置的一部分:

<servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> --> 
     <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    ... 
    <listener> 
     <listener- class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
    </listener> 

有沒有人遇到過類似的錯誤,而我應該怎麼我是否爲了解決它?感謝名單!

編輯:

我能解決這個問題。由於我使用的委託人爲FacesServlet,事實證明,這個委託人造成了這個問題。 我需要做的就是讓這個類實現DelegatedFacesServlet,並且我已經刪除了org.apache.myfaces.webapp.StartupServletContextListener。這是我的web.xml現在:

<servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> --> 
     <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet> 
     <servlet-name>Faces Servlet Delegator</servlet-name> 
     <servlet-class>com.myapp.web.FacesServletDelegator</servlet-class> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Faces Servlet Delegator</servlet-name> 
     <url-pattern>*.jsf</url-pattern> 
    </servlet-mapping> 

,這裏是FacesServletDelegator

public class PLMFacesServlet extends HttpServlet implements DelegatedFacesServlet { 

    private MyFacesServlet delegate; 

    public final void init(ServletConfig servletConfig) throws ServletException { 
     delegate = new MyFacesServlet(); 
     delegate.init(servletConfig); 
    } 

    public final void destroy() { 
     delegate.destroy(); 
    } 

    public final ServletConfig getServletConfig() { 
     return delegate.getServletConfig(); 
    } 

    public final String getServletInfo() { 
     return delegate.getServletInfo(); 
    } 

    public final void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { 

     try { 
      delegate.service(request, response); 
     } catch(Exception e) {} 
    } 
    // some other code... 
} 

編輯2

BalusC的建議,我已經編輯我的網.xml有點,這裏是最終版本:

<servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet> 
    <servlet-name>Faces Servlet Delegator</servlet-name> 
    <servlet-class>com.myapp.web.FacesServletDelegator</servlet-class> 
    <load-on-startup>2</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Faces Servlet Delegator</servlet-name> 
    <url-pattern>*.jsf</url-pattern> 
</servlet-mapping> 
+0

我不做MyFaces的,但我其實非常* *驚訝,你顯然需要outcomment指定的JSF 2.0 API'< servlet-class> javax.faces.webapp.FacesServlet'並使用MyFaces特定的一個。這意味着MyFaces與JSF 2.0 API不兼容。或者這只是你的無知?撤消那個outcomment並擺脫MyFaces impl特定的聲明並重試。它工作嗎? – BalusC

+0

它正在工作。 Thanx BalusC指出了這一點。當我搜索可能是最初問題的原因時,我可能也會做出這種改變。我將根據您的建議編輯我的問題...... – Igor

+2

只需回覆以前的評論並說明問題,MyFaces Core與JSF 2.0 API 100%兼容,因爲在每次發佈前都會進行一些測試。覆蓋默認的標準FacesServlet並使用一個代表實現特定的代表,這意味着它是一個「規範之外」的破解。有一些有效的用例可以做到這一點,但作爲一種「最佳實踐」,您不應該依賴這一點。如果您對MyFaces有更多疑問,可以另外向[MyFaces用戶和開發郵件列表](http://myfaces.apache.org/mail-lists.html)詢問。 – lu4242

回答

4

在我的情況下,去除從我的web.xml以下行:

<load-on-startup>1</load-on-startup> 

......是什麼讓錯誤消失。

(正在修理一個純粹的Tomcat 7使用JSF)。

相關問題