title: spring boot - how to correctly define template locations?
body: <p>After struggling for some time with a Spring app (and spring boot, for that matter), it seems I'm finally about to get it working.</p>
  
  <p>I have shifted through dependency resolutions and maven build already. Application starts (and very quickly!) but when I try to access </p>
  
  <p><code>localhost:8080</code></p>
  
  <p>I get the following browser message whenever I try to reach the application's landing page:</p>
  
  <pre><code>HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "home/homeNotSignedIn", template might not exist or might not be accessible by any of the configured Template Resolvers
  </code></pre>
  
  <p>The <code>src/main/resources</code>folder is </p>
  
  <pre><code>src/main/resources
      static // CSS, IMG and JS
      templates // html
      application.properties
      log4j.properties
  </code></pre>
  
  <p>Now, I understand I may be mixing concepts, but on my <code>ApplicationConfiguration.java</code> I have this:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "b.c.g.c")
  public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
  
      @Bean
      @Description("Thymeleaf template resolver serving HTML 5")
      public ServletContextTemplateResolver templateResolver() {
          ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
          templateResolver.setCacheable(false);
          templateResolver.setTemplateMode("HTML5");
          templateResolver.setCharacterEncoding("UTF-8");
          templateResolver.setPrefix("classpath:/templates/");
          templateResolver.setSuffix(".html");
  
          return templateResolver;
      }
  
      @Bean
      @Description("Thymeleaf template engine with Spring integration")
      public SpringTemplateEngine templateEngine() {
          SpringTemplateEngine templateEngine = new SpringTemplateEngine();
          templateEngine.addDialect(new SpringSecurityDialect());
          templateEngine.addDialect(new LayoutDialect(new GroupingStrategy()));
          templateEngine.setTemplateResolver(templateResolver());
  
          return templateEngine;
      }
  
      @Bean
      @Description("Thymeleaf view resolver")
      public ViewResolver viewResolver() {
  
          ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
          viewResolver.setTemplateEngine(templateEngine());
          viewResolver.setCharacterEncoding("UTF-8");
          viewResolver.setCache(false);
          viewResolver.setOrder(1);
  
          return viewResolver;
      }
  
      // other beans
  }
  </code></pre>
  
  <p>And, on <code>application.properties</code>, I have this:</p>
  
  <pre><code>spring.thymeleaf.check-template-location=true
  spring.thymeleaf.prefix=classpath:templates/
  spring.thymeleaf.suffix=.html
  spring.thymeleaf.mode=HTML5
  spring.thymeleaf.encoding=UTF-8
  spring.thymeleaf.content-type=text/html
  spring.thymeleaf.cache=false
  </code></pre>
  
  <p>Though I see these excerpts tell the same thing, I bet one can go, right?</p>
  
  <p>So, two questions, actually, </p>
  
  <p>1) how to make sure Spring + Thymeleaf understand where to find the templates?</p>
  
  <p>2) how to get the application to answer to <code>localhost:8080/appName</code> instead of <code>localhost:8080/</code>?</p>