在JSF应用程序中嵌入Undertow时javax.faces.context.FacesContextFactory异常 [英] javax.faces.context.FacesContextFactory Exception while embedding Undertow with JSF application

查看:177
本文介绍了在JSF应用程序中嵌入Undertow时javax.faces.context.FacesContextFactory异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to build a simple JSF web application using embedded Undertow server.

项目的等级依赖性:

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服务器代码示例:

Sample Undertow Server Code:

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

    }
}

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

When i start the server,following error comes:

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)

推荐答案

最后我找到了解决方案.

Finally i found a solution.

对于JSF引导过程,我们必须在Undertow DeploymentInfo类中添加两个附加的init参数.

For JSF bootstrap process we must add Two additional init parameter to Undertow DeploymentInfo class.

  1. com.sun.faces.forceLoadConfiguration = TRUE
  2. com.sun.faces.expressionFactory = com.sun.el.E​​xpressionFactoryImpl

我们还必须添加除JSF之外的两个额外的依赖项.

Also we must add two more extra dependency other than JSF.

  1. el-api
  2. el-impl

这篇关于在JSF应用程序中嵌入Undertow时javax.faces.context.FacesContextFactory异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆