title: How to integrate spring boot with JSF 2.2 with embedded tomcat
body: <p>I'm trying to integrate spring boot with JSF in embedded tomcat with no luck, I tried with two approaches one with web.xml and other with Java config. In both cases xhtml pages are not getting rendered, instead a blank page is getting rendered. Below are configurations.</p>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.kp.swasthik&lt;/groupId&gt;
      &lt;artifactId&gt;kp-sb-jsf&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;kp-sb-jsf&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.3.0.M5&lt;/version&gt;
          &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;primefaces.version&gt;5.2&lt;/primefaces.version&gt;
          &lt;!-- &lt;jsf.version&gt;2.2.8&lt;/jsf.version&gt; --&gt;
          &lt;jsf.version&gt;2.2.12&lt;/jsf.version&gt;
          &lt;jsf.extension.version&gt;3.2.0&lt;/jsf.extension.version&gt;
          &lt;jsf.themes.version&gt;1.0.10&lt;/jsf.themes.version&gt;
          &lt;spring.webflow.version&gt;2.4.2.RELEASE&lt;/spring.webflow.version&gt;
          &lt;omnifaces.version&gt;2.1&lt;/omnifaces.version&gt;
          &lt;wield.version&gt;2.2.15.Final&lt;/wield.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
          &lt;version&gt;3.1.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet.jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.3.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.el&lt;/groupId&gt;
          &lt;artifactId&gt;javax.el-api&lt;/artifactId&gt;
          &lt;version&gt;3.0.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.web&lt;/groupId&gt;
          &lt;artifactId&gt;el-impl&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
      &lt;/dependency&gt;
  
         &lt;!--
          &lt;dependency&gt;
              &lt;groupId&gt;org.omnifaces&lt;/groupId&gt;
              &lt;artifactId&gt;omnifaces&lt;/artifactId&gt;
              &lt;version&gt;${omnifaces.version}&lt;/version&gt;
          &lt;/dependency&gt;
         --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.weld.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;weld-servlet&lt;/artifactId&gt;
              &lt;version&gt;${wield.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;commons-io&lt;/groupId&gt;
              &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
              &lt;version&gt;2.4&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.primefaces&lt;/groupId&gt;
              &lt;artifactId&gt;primefaces&lt;/artifactId&gt;
              &lt;version&gt;${primefaces.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.primefaces.extensions&lt;/groupId&gt;
              &lt;artifactId&gt;primefaces-extensions&lt;/artifactId&gt;
              &lt;version&gt;${jsf.extension.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.primefaces.themes&lt;/groupId&gt;
              &lt;artifactId&gt;all-themes&lt;/artifactId&gt;
              &lt;version&gt;${jsf.themes.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.primefaces.extensions&lt;/groupId&gt;
              &lt;artifactId&gt;resources-optimizer-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.0.0&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- &lt;dependency&gt; &lt;groupId&gt;org.apache.myfaces.core&lt;/groupId&gt; &lt;artifactId&gt;myfaces-impl&lt;/artifactId&gt; 
              &lt;version&gt;${jsf.version}&lt;/version&gt; &lt;/dependency&gt; --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
              &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
              &lt;version&gt;${jsf.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
              &lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
              &lt;version&gt;${jsf.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
              &lt;artifactId&gt;spring-faces&lt;/artifactId&gt;
              &lt;version&gt;${spring.webflow.version}&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                      &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webflow&lt;/artifactId&gt;
              &lt;version&gt;${spring.webflow.version}&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                      &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
              &lt;artifactId&gt;spring-binding&lt;/artifactId&gt;
              &lt;version&gt;${spring.webflow.version}&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                      &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-snapshots&lt;/id&gt;
              &lt;name&gt;Spring Snapshots&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/snapshot&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;name&gt;Spring Milestones&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;false&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt;
          &lt;repository&gt;
              &lt;id&gt;prime-repo&lt;/id&gt;
              &lt;name&gt;PrimeFaces Maven Repository&lt;/name&gt;
              &lt;url&gt;http://repository.primefaces.org&lt;/url&gt;
              &lt;layout&gt;default&lt;/layout&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
      &lt;pluginRepositories&gt;
          &lt;pluginRepository&gt;
              &lt;id&gt;spring-snapshots&lt;/id&gt;
              &lt;name&gt;Spring Snapshots&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/snapshot&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/pluginRepository&gt;
          &lt;pluginRepository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;name&gt;Spring Milestones&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;false&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/pluginRepository&gt;
      &lt;/pluginRepositories&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>faces.config in src/main/resources/META-INF directory</strong></p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
      &lt;faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" metadata-complete="false" &gt;
  
          &lt;application&gt;
              &lt;el-resolver&gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&lt;/el-resolver&gt;
              &lt;!-- &lt;resource-handler&gt;org.omnifaces.resourcehandler.CombinedResourceHandler&lt;/resource-handler&gt; --&gt;
              &lt;resource-handler&gt;org.omnifaces.resourcehandler.UnmappedResourceHandler&lt;/resource-handler&gt;
  
  
      &lt;/application&gt;
  
      &lt;lifecycle&gt;
          &lt;phase-listener&gt;org.springframework.web.jsf.DelegatingPhaseListenerMulticaster&lt;/phase-listener&gt;
      &lt;/lifecycle&gt;
  
  &lt;/faces-config&gt;
  </code></pre>
  
  <p><strong>context.xml for wield in src/main/webapp/META-INF</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context&gt;
      &lt;Resource name="BeanManager" auth="Container"
          type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" /&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>Index.html moved to src/main/resources/META-INF/resources
  <strong>index.xhtml</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"&gt;
  
  &lt;h:head&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;p:panel&gt;
           #{kpDisplay.hello}
       &lt;/p:panel&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  
  @SpringBootApplication
  @ComponentScan(basePackages={"com.kp.swasthik.bjsf"})
  public class KpSbBjsfApplication extedns SpringBootServletInitializer{
  
  
      public static void main(String[] args) {
          SpringApplication.run(KpSbBjsfApplication.class, args);
      }    
  
       @Override
       protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(KpSbBjsfApplication.class);
    } 
  
    @Bean
  public ServletRegistrationBean facesServletRegistration() {
  
      ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new FacesServlet(), "*.xhtml");
      servletRegistrationBean.addUrlMappings("/faces/*");
      servletRegistrationBean.setLoadOnStartup(1);
      return servletRegistrationBean;
  }
  
  @Bean
  public ServletListenerRegistrationBean&lt;ConfigureListener&gt; jsfConfigureListener() {
      return new ServletListenerRegistrationBean&lt;ConfigureListener&gt;(new ConfigureListener());
  }
  
  @Bean
  @ConditionalOnMissingBean
  public RequestContextListener getRequestContextListener() {
      return new RequestContextListener();
  }
  }
  </code></pre>
  
  <p>And servlet context init class.</p>
  
  <pre><code>public class ServletCustmContextInitializer implements ServletContextInitializer {
  
      @Override
      public void onStartup(ServletContext jsfServlet) throws ServletException {
     jsfServlet.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
      jsfServlet.setInitParameter("javax.faces.PARTIAL_STATE_SAVING_METHOD", "true");
      jsfServlet.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
      jsfServlet.setInitParameter("facelets.DEVELOPMENT", "true");
      jsfServlet.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "1");
      jsfServlet.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
      jsfServlet.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
      jsfServlet.setInitParameter("primefaces.THEME", "bootstrap");
  
      }
  
  }
  </code></pre>
  
  <p>I managed to bring up jsf-spring boot configuration but now JSF annotations does not work. If I add managed annotations manually to faces-config.xml the managed annotations do work.  I even added metadata-complete="false" so the jsf scans for annotations sadly it doesn't work</p>