2017-03-07 44 views
1

我正嘗試使用嵌入式Undertow服務器構建一個簡單的JSF Web應用程序。javax.faces.context.FacesContextFactory使用JSF應用程序嵌入Undertow時出現異常

搖籃相依項目爲:

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' 

} 

樣品暗潮服務器代碼:

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) 
+0

你確定你既包括JSF API和實現?或者,也許(偶然)只有api? – Kukeltje

+0

是@Kukeltje。我正在使用[glassfish jar](http://mvnrepository.com/artifact/org.glassfish/javax.faces/2.2.11),其中包括api和impl。 – Parin

+0

發現WildFly Server報告的一個問題https://issues.jboss.org/browse/WFLY-6010 – Parin

回答

0

終於讓我找到一個解。

對於JSF引導進程,我們必須爲Undertow DeploymentInfo類添加兩個額外的init參數。

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

同時,我們也必須添加比JSF其他兩個額外的依賴。

  1. EL-API
  2. EL-IMPL
相關問題