javax.faces.context.FacesContextFactory嵌入Undertow与JSF应用程序时的异常

时间:2017-03-07 12:55:10

标签: jsf spring-boot jsf-2 undertow

我正在尝试使用嵌入式Undertow服务器构建一个简单的JSF Web应用程序。

项目的Gradle依赖项:

dependencies {

               compile group: 'io.undertow', name: 'undertow-core',    version: '1.4.0.CR3'
               compile group: 'io.undertow', name: 'undertow-servlet', version: '1.4.0.CR3'
               compile group: 'javax', name: 'javaee-api', version: '7.0'
               compile group: 'org.glassfish', name: 'javax.faces', version: '2.2.11'

}

示例Undertow服务器代码:

public class HelloWorldServer {

    public static void main(final String[] args) throws ServletException {

        DeploymentInfo servletContainer=Servlets.deployment()
                .setClassLoader(HelloWorldServer.class.getClassLoader())
                .setDeploymentName("helloWorld.war")
                .setContextPath("")
                .addServlet(Servlets.servlet("javax.faces.webapp.FacesServlet",FacesServlet.class)
                .addMappings("/faces/*","/javax.faces.resource/*")
                .setLoadOnStartup(1));
        DeploymentManager manager=Servlets.defaultContainer().addDeployment(servletContainer);
        manager.deploy();
        HttpHandler servletHandler=manager.start();
        PathHandler path = Handlers.path(Handlers.redirect(""))
                    .addPrefixPath("/", servletHandler);

         Undertow server = Undertow.builder()
                    .addHttpListener(8080, "localhost")
                    .setHandler(path)
                    .build();
            server.start();

    }
}

当我启动服务器时,出现以下错误:

Mar 07, 2017 6:04:49 PM javax.faces.FactoryFinder$FactoryManager copyInjectionProviderFromFacesContext
SEVERE: Unable to obtain InjectionProvider from init time FacesContext. Does this container implement the Mojarra Injection SPI?
Mar 07, 2017 6:04:49 PM javax.faces.FactoryFinder$FactoryManager getFactory
SEVERE: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory. Attempting to find backup.
Exception in thread "main" java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory. 
    at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1135)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:379)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:350)
    at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
    at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:239)
    at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:133)
    at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:541)
    at HelloWorldServer.main(HelloWorldServer.java:24)

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案。

对于JSF引导程序,我们必须在Undertow DeploymentInfo类中添加两个额外的init参数。

  1. com.sun.faces.forceLoadConfiguration = TRUE
  2. com.sun.faces.expressionFactory = com.sun.el.E​​xpressionFactoryImpl
  3. 此外,除了JSF之外,我们还必须添加两个额外的依赖项。

    1. EL-API
    2. EL-IMPL