Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Servlets 找不到工厂:javax.faces.context.FacesContextFactory_Servlets_Jsf 2_Jetty_Maven Jetty Plugin - Fatal编程技术网

Servlets 找不到工厂:javax.faces.context.FacesContextFactory

Servlets 找不到工厂:javax.faces.context.FacesContextFactory,servlets,jsf-2,jetty,maven-jetty-plugin,Servlets,Jsf 2,Jetty,Maven Jetty Plugin,我注意到,当尝试设置在jetty上运行的JSF 2 webapp时,出现以下错误: java.lang.IllegalStateException:应用程序未正确运行 启动时初始化,找不到工厂: javax.faces.context.FacesContextFactory 通过将其添加到我的web.xml中,可以很容易地解决这个问题 <listener> <listener-class> com.sun.faces.config.Configur

我注意到,当尝试设置在jetty上运行的JSF 2 webapp时,出现以下错误:

java.lang.IllegalStateException:应用程序未正确运行 启动时初始化,找不到工厂: javax.faces.context.FacesContextFactory

通过将其添加到我的web.xml中,可以很容易地解决这个问题

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

com.sun.faces.config.ConfigureListener
我试图寻找一个详细的解释,但徒劳无功

JettyMaven插件:8.0.3.v20111011:run+JDK7+EclipseIndigo

这是我对maven的依赖:

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

玻璃鱼
javax.faces
2.1.3
编译
以下是我的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>

基本设置Web应用程序
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
/面孔/*
faces/index.xhtml
com.sun.faces.config.ConfigureListener
javax.faces.PROJECT_阶段
发展
下面是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.

[INFO]这个监听器是因为jsf1.x应该由
JSF_core.tld
标记库定义文件自动注册的。您可以在JSF实现JAR文件的
/META-INF
文件夹中找到它。对于Mojarra 2.1.3(您似乎是根据日志使用的),监听器从第80行开始注册如下:


com.sun.faces.config.ConfigureListener
然而,码头显然没有正确地处理这一问题。我还从某个地方读到,当在处理TLD文件之前初始化
FacesServlet
时,您也会得到这个异常。也许这是发生在码头。要排除一个和另一个,请尝试删除
条目,以便仅在处理TLD之后的第一个具体HTTP请求时加载它。无论如何,在
web.xml
中显式注册侦听器确实可以解决这个问题

此外,由于JSF2.x,除了TLD文件之外,侦听器还应该由JAR文件中的实现自动注册,以便解决Glassfish 3错误。在Mojarra 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、Jetty 8(据说是!)等。您似乎正在使用Jetty 8.0,因此它应该符合Servlet 3.0,但您的
web.xml
声明为符合Servlet 2.5,因此容器将在Servlet 2.5回退模式下运行。更改
web.xml
以符合Servlet 3.0应触发此初始值设定项。

再解决一个问题: 在使用来自wsdl的CXF动态创建java文件后,我遇到了这个错误

JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL, serviceName);
CXF将自己的类加载器(URLClassLoader的实例)放入线程的类加载器。它以正常的方式工作,直到用户的线程进入JSF的FactoryFinder,它作为键被类加载器缓存。 由于类加载器已更改,它将创建一个无法初始化的新FactoryManager,因为在原始FactoryManager启动时将删除实现实例列表。因此,找不到实现类,因此抛出IllegalStateException

解决方案:在CXF的createClient之前备份原始类加载器,将URLClassLoader保存在变量中,并将原始类加载器放回线程。
当您想从CXF访问动态类时,请通过您放入变量中的URLClassLoader进行搜索。

我在项目中遇到了这个问题,包括两个jar文件到lib文件夹,现在我的问题得到了解决。谢谢

faces:jsfapi:2.2.9
com.sun.faces:jsf impl:2.2.9

你有mojarra依赖关系吗?@Bozho:我想是的,因为只要添加listener标签就可以让它工作,我尝试过在启动时移除负载和切换到3.0,但仍然失败。我认为是时候再次转到tomcat7来测试一下了。我正考虑使用jetty,因为它能够通过maven插件快速部署。稍后我会找到其他方法让这些在tomcat7中工作。非常感谢。启用Jetty 8“annotations”功能后,我发现Jetty使用了GlassFish的Jasper版本,该版本故意跳过TLD文件中定义的Mojarra ConfigureListener。此外,如果FacesServlet是在web.xml中定义的,Mojarra FacesInitializer将不会注册Mojarra ConfigureListener。我通过注册一个定制的ServletContainerInitializer实现了这一点。有关详细信息,请参阅和。@Neil:很好的发现!这确实解释了这种行为。杰蒂最好从Tomcat那里借Jasper,或者自己开发。@BalusC:谢谢你对Bauke说的客气话。我还发现,将jsf-api.jar和jsf-impl.jar添加到$JETTY_HOME/lib/jsp是将mojara添加到JETTY全局类路径的一种方式,这将导致JETTY自动注册ConfigureListener。请注意,必须启用“注释”功能。