title: Simple Primefaces app with Spring boot
body: <p>Just started working with <strong>Spring Boot</strong> and I'm trying to create a simple application using <strong>Primefaces</strong>, but I can't find a way to show my <code>.xhtml</code> views.</p>
  
  <p>When I access to <code>localhost:8080</code> I get the <em>Whitelabel Error Page</em> with the next error:</p>
  
  <blockquote>
    <p>There was an unexpected error (type=Not Found, status=404).</p>
  </blockquote>
  
  <p>I used to have my views on <code>src/main/webapp/WEB-INF/views/</code> but I understand that with the use of the <code>fat jar</code> for Spring boot apps now I have to place my views on <code>src/main/resources</code>, but I'm not sure if I still have to use <code>ViewResolver</code>.</p>
  
  <p><strong>/src/main/java/Application.java:</strong></p>
  
  <pre><code>@SpringBootApplication
  public class Application {
  
      /*@Bean
      public ViewResolver setupViewResolver() {
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setPrefix("/views/");
          resolver.setSuffix(".xhtml");
          return resolver;
      }*/
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);    
          System.out.println("INITIALIZED");
      }
  
  }
  </code></pre>
  
  <p><strong>/src/main/java/BaseController.java:</strong></p>
  
  <pre><code>@Controller
  public class BaseController{
  
      private static final String VIEW_INDEX = "index";
  
      @RequestMapping("/")
      public String welcome(ModelMap model) {
          return VIEW_INDEX;
      }
  }
  </code></pre>
  
  <p><strong>/src/main/resources/views/index.xhtml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"&gt;
  
  &lt;h:head&gt;
      &lt;title&gt;Application&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;h1&gt;TEST&lt;/h1&gt;
      &lt;p:spinner&gt;&lt;/p:spinner&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>/src/main/resources/faces-config.xml:</strong></p>
  
  <pre><code>&lt;faces-config 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"
      version="2.2"&gt;
  
  &lt;/faces-config&gt;
  </code></pre>
  
  <p><strong>Spring-boot log:</strong></p>
  
  <pre><code>  .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v1.4.2.RELEASE)
  
  2016-11-18 13:16:58.511  INFO 6384 --- [           main] c.crivero.cloudfoundry_test.Application  : Starting Application v0.0.1 on XXX with PID 6384 (C:\Users\criverom\Documents\EclipseWorkspace\cloudfoundry-test\target\cloudfoundry-test-0.0.1.jar started by criverom in C:\Users\criverom\Documents\EclipseWorkspace\cloudfoundry-test)
  2016-11-18 13:16:58.550  INFO 6384 --- [           main] c.crivero.cloudfoundry_test.Application  : No active profile set, falling back to default profiles: default
  2016-11-18 13:16:58.725  INFO 6384 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.Annotat
  ionConfigEmbeddedWebApplicationContext@1698c449: startup date [Fri Nov 18 13:16:58 CET 2016]; root of context hierarchy
  2016-11-18 13:17:03.160  INFO 6384 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
  2016-11-18 13:17:03.195  INFO 6384 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
  2016-11-18 13:17:03.199  INFO 6384 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
  2016-11-18 13:17:03.414  INFO 6384 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2016-11-18 13:17:03.415  INFO 6384 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4695 ms
  2016-11-18 13:17:03.830  INFO 6384 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
  2016-11-18 13:17:03.839  INFO 6384 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
  2016-11-18 13:17:03.840  INFO 6384 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2016-11-18 13:17:03.840  INFO 6384 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  2016-11-18 13:17:03.841  INFO 6384 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
  2016-11-18 13:17:04.232  INFO 6384 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1698c449: startup date [Fri Nov 18 13:16:58 CET 2016]; root of context hierarchy
  2016-11-18 13:17:04.458  INFO 6384 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.crivero.cloudfoundry_test.BaseController.welcome(org.springframework.ui.ModelMap)
  2016-11-18 13:17:04.469  INFO 6384 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
  2016-11-18 13:17:04.470  INFO 6384 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
  2016-11-18 13:17:04.564  INFO 6384 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2016-11-18 13:17:04.567  INFO 6384 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2016-11-18 13:17:04.641  INFO 6384 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2016-11-18 13:17:05.060  INFO 6384 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
  2016-11-18 13:17:05.197  INFO 6384 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
  2016-11-18 13:17:05.209  INFO 6384 --- [           main] c.crivero.cloudfoundry_test.Application  : Started Application in 7.94 seconds (JVM running for 8.895)
  INITIALIZED
  2016-11-18 13:18:44.775  INFO 6384 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
  2016-11-18 13:18:44.775  INFO 6384 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
  
  2016-11-18 13:18:44.815  INFO 6384 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 39 ms
  </code></pre>