2011-10-25 80 views
20

我注意到,試圖安裝在碼頭上運行我的JSF 2 web應用程序的時候,我有這樣的錯誤:找不到廠:javax.faces.context.FacesContextFactory

java.lang.IllegalStateException:應用程序不正確 在啓動時初始化,也找不到廠家: javax.faces.context.FacesContextFactory

這是很容易通過添加這個對我的web.xml解決

<listener> 
    <listener-class> 
     com.sun.faces.config.ConfigureListener 
    </listener-class> 
</listener> 

我試圖尋找一個詳細的解釋,但徒勞無功..

碼頭 - Maven的插件:8.0.3.v20111011:運行+ JDK 7 +日食靛藍

這是我的Maven的依賴關係:

<dependencies> 
    <dependency> 
     <groupId>org.glassfish</groupId> 
     <artifactId>javax.faces</artifactId> 
     <version>2.1.3</version> 
     <scope>compile</scope> 
    </dependency> 
</dependencies> 

這裏是我的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_2_5.xsd" 
    version="2.5"> 
    <display-name>Basic Setup Web Application</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>/faces/*</url-pattern> 
    </servlet-mapping> 
    <welcome-file-list> 
     <welcome-file>faces/index.xhtml</welcome-file> 
    </welcome-file-list> 
    <listener> 
     <listener-class> 
      com.sun.faces.config.ConfigureListener 
     </listener-class> 
    </listener> 
    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 
</web-app> 

和這裏的碼頭插件的輸出:

[INFO] <<< jetty-maven-plugin:8.0.3.v20111011:run (default-cli) @ BasicSetup <<< 
[INFO] 
[INFO] --- jetty-maven-plugin:8.0.3.v20111011:run (default-cli) @ BasicSetup --- 
[INFO] Configuring Jetty for project: BasicSetup Maven Webapp 
[INFO] webAppSourceDirectory C:\Users\albert\workspace\BasicSetup\src\main\webapp does not exist. Defaulting to C:\Users\albert\workspace\BasicSetup\src\main\webapp 
[INFO] Reload Mechanic: automatic 
[INFO] Classes = C:\Users\albert\workspace\BasicSetup\target\classes 
[INFO] Context path = /basicSetup 
[INFO] Tmp directory = C:\Users\albert\workspace\BasicSetup\target\tmp 
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml 
[INFO] Web overrides = none 
[INFO] web.xml file = file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/WEB-INF/web.xml 
[INFO] Webapp directory = C:\Users\albert\workspace\BasicSetup\src\main\webapp 
2011-10-25 14:24:51.091:INFO:oejs.Server:jetty-8.0.3.v20111011 
2011-10-25 14:24:51.334:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one. 
2011-10-25 14:24:52.108:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/basicSetup,[file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/, jar:file:/C:/Users/albert/.m2/repository/org/glassfish/javax.faces/2.1.3/javax.faces-2.1.3.jar!/META-INF/resources/]},file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/ 
2011-10-25 14:24:52.108:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/basicSetup,[file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/, jar:file:/C:/Users/albert/.m2/repository/org/glassfish/javax.faces/2.1.3/javax.faces-2.1.3.jar!/META-INF/resources/]},file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/ 
2011-10-25 14:24:52.108:INFO:oejsh.ContextHandler:started o.m.j.p.JettyWebAppContext{/basicSetup,[file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/, jar:file:/C:/Users/albert/.m2/repository/org/glassfish/javax.faces/2.1.3/javax.faces-2.1.3.jar!/META-INF/resources/]},file:/C:/Users/albert/workspace/BasicSetup/src/main/webapp/ 
2011-10-25 14:24:52.149:WARN:/basicSetup:unavailable 
java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory 
    at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:967) 
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:316) 
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:302) 
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:456) 
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:276) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:779) 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:255) 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1212) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453) 
    at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:256) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224) 
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89) 
    at org.eclipse.jetty.server.Server.doStart(Server.java:262) 
    at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511) 
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364) 
    at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:514) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534) 
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 
[INFO] Started Jetty Server 
2011-10-25 14:24:52.165:INFO:oejs.AbstractConnector:Started [email protected]:8080 STARTING 
[INFO] Starting scanner at interval of 10 seconds. 

有什麼想法?

+0

你有沒有鑽嘴魚科的依賴? – Bozho

+0

@Bozho:我認爲是的,因爲僅僅通過增加監聽器標籤使得它的工作 – bertie

回答

28

此監聽器自JSF 1.x應該由jsf_core.tld標記庫定義文件自動註冊。您可以在JSF實現JAR文件的/META-INF文件夾中找到它。在鑽嘴魚科2.1.3(你似乎根據日誌中使用)的情況下,註冊偵聽來自線80和如下:

<!-- ============== Configuration Listener ============== --> 

<!-- 
     This ServletContextListener initializes the runtime environment 
     of the JavaServer Faces Reference Implementation when a web 
     application including it is initialized by the container. 
--> 
<listener> 
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class> 
</listener>  

然而,這顯然是不正確的碼頭回升。我也讀過一些地方,當FacesServlet被初始化之前 TLD文件已被處理,那麼你也會得到這個例外。也許這是發生在碼頭。要排除其中的一個,請嘗試刪除<load-on-startup>條目,以便僅在第一個具體的HTTP請求中加載該條目,遠遠超過TLD處理的時間。無論如何,在web.xml中顯式註冊監聽器應該可以解決這個問題。

此外,由於JSF 2.x中,除了TLD文件,收聽者也應該被自動地通過在JAR文件中的ServletContainerInitializer執行以解決辦法一個Glassfish的3錯誤註冊。在鑽嘴魚科2.X是這種com.sun.faces.config.FacesInitializer類,其具有起始於線131以下行:(!據說)

// The following line is temporary until we can solve an ordering 
// issue in V3. Right now the JSP container looks for a mapping 
// of the FacesServlet in the web.xml. If it's not present, then 
// it assumes that the application isn't a faces application. In this 
// case the JSP container will not register the ConfigureListener 
// definition from our TLD nor will it parse cause or JSP TLDs to 
// be parsed. 
servletContext.addListener(com.sun.faces.config.ConfigureListener.class); 

此工程中的Servlet僅3.0容器,如Tomcat 7,Glassfish的3,碼頭8,等等。您似乎在使用Jetty 8.0,因此它應符合Servlet 3.0,但您的web.xml已聲明符合Servlet 2.5,因此容器將以Servlet 2.5後備模式運行。改變你的web.xml以符合Servlet 3.0應該會觸發這個初始化器。

+0

我曾經嘗試都去掉時加載的啓動和切換到3.0,但仍與相同的故障。我認爲是時候再次轉向tomcat7來測試一下。我正在考慮使用碼頭,因爲它能夠快速部署與maven插件的爆炸戰爭。我會找到其他方法讓這些在tomcat7以後工作。謝謝 ! – bertie

+0

不客氣。 – BalusC

+0

啓用Jetty 8「註釋」功能後,我發現Jetty使用GlassFish中的Jasper版本,故意跳過在TLD文件中定義的Mojarra ConfigureListener。此外,如果FacesServlet是web.xml中定義的鑽嘴魚科FacesInitializer不會註冊鑽嘴魚科ConfigureListener。我通過註冊一個自定義的ServletContainerInitializer來完成它的工作。有關更多詳細信息,請參閱[在Jetty上部署JSF Portlet](http://www.liferay.com/community/wiki/-/wiki/Main/Deploying+JSF+Portlets+on+Jetty)和[FACES-1668]( http://issues.liferay.com/browse/FACES-1668)。 –

0

還有一個解決方案: 我在使用wsdl的CXF動態創建java文件後出現此錯誤。

JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(); 
Client client = factory.createClient(wsdlURL, serviceName); 

CXF將自己的ClassLoader(URLClassLoader的實例)放到Thread的類加載器中。它以正常的方式工作,直到用戶的線程進入JSF的FactoryFinder,由ClassLoader緩存爲關鍵字。 因爲ClassLoader的改變,它會創建一個新的FactoryManager,不能初始化,因爲當原FactoryManager發起的執行情況表被刪除。正因爲如此,實現類沒有找到,因此拋出了IllegalStateException。

解決方案:備份CXF的createClient之前的原始類加載器,保存在一個變量的URLClassLoader並放回原來的ClassLoader的主題。 當你想從CXF訪問動態類,搜索它通過你把一個變量的URLClassLoader。

相關問題