23

jetty で実行されている JSF 2 webapp をセットアップしようとすると、次のエラーが発生することに気付きました。

java.lang.IllegalStateException: アプリケーションは起動時に正しく初期化されていませんでした。Factory が見つかりませんでした: javax.faces.context.FacesContextFactory

これを私のweb.xmlに追加することで簡単に解決できます

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

詳細な説明を検索しようとしましたが、無駄です..

jetty-maven-plugin:8.0.3.v20111011:run + 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>

そしてこれがjettyプラグインの出力です:

[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 SelectChannelConnector@0.0.0.0:8080 STARTING
[INFO] Starting scanner at interval of 10 seconds.

何かご意見は ?

4

3 に答える 3

30

このリスナーは、JSF 1.x 以降、jsf_core.tldタグ ライブラリ定義ファイルによって自動的に登録されることになっています。これは/META-INF、JSF 実装 JAR ファイルのフォルダーにあります。Mojarra 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>      

ただし、これは Jetty によって適切に検出されていないようです。また、TLD ファイルが処理される前にFacesServletが初期化されると、まさにこの例外が発生することもどこかで読みました。おそらくこれはJettyで起こっています。どちらか一方を除外するには、TLD が処理されてからずっと後の最初の具体的な HTTP 要求でのみ読み込まれるように、エントリを削除してみてください。いずれにせよ、リスナーを明示的に登録することで実際に解決するはずです。<load-on-startup>web.xml

さらに、JSF 2.x 以降では、TLD ファイルに加えてServletContainerInitializer、Glassfish 3 のバグを回避するためにリスナーも JAR ファイルの実装によって自動的に登録されることになっています。Mojarra 2.x では、これはcom.sun.faces.config.FacesInitializer131 行目から始まる次の行を持つクラスです。

// 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);

これは、Tomcat 7、Glassfish 3、Jetty 8 (おそらく!) などの Servlet 3.0 コンテナーでのみ機能します。Jetty 8.0 を使用しているため、Servlet 3.0 に準拠しているようですが、web.xmlServlet 2.5 に準拠していると宣言されているため、コンテナーはサーブレット 2.5 フォールバック方式で実行されます。web.xmlサーブレット 3.0 に準拠するように変更すると、この初期化子がトリガーされます。

于 2011-10-25T13:20:36.790 に答える
0

もう 1 つの解決策: wsdl から CXF を使用してオンザフライで Java ファイルを作成した後、このエラーが発生しました。

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

CXF は独自の ClassLoader (URLClassLoader のインスタンス) を Thread のクラスローダーに配置します。ユーザーのスレッドが、ClassLoader によってキーとしてキャッシュされる JSF の FactoryFinder に入るまで、通常の方法で動作します。ClassLoader が変更されたため、元の FactoryManager が開始されたときに実装インスタンス リストが削除されるため、初期化できない新しい FactoryManager が作成されます。そのため、実装クラスが見つからないため、IllegalStateException がスローされます。

解決策: CXF の createClient の前に元の ClassLoader をバックアップし、URLClassLoader を変数に保存して、元の ClassLoader を Thread に戻します。CXF から動的クラスにアクセスしたい場合は、変数に入れた URLClassLoader で検索します。

于 2016-04-06T09:07:57.840 に答える