title: Spring Boot gives "TemplateInputException: Error resolving template" when running from jar
body: <p>I have an app that works perfectly when started within IntelliJ or via gradle bootRun.</p>
  
  <p>however, if I do gradle bootRepackage and then try and run the resulting jar, I end up with:</p>
  
  <pre><code>2014-12-02 21:46:14.086 ERROR 9839 --- [nio-2014-exec-2] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-2014-exec-2] Exception processing template "/login": Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers
  2014-12-02 21:46:14.087 ERROR 9839 --- [nio-2014-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
  
  org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers
      at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
      at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)
  </code></pre>
  
  <p>I can see that the jar has /templates/** contained in it. the content looks OK to me.</p>
  
  <p>One <em>possible</em>(?) factor may be that I use an html page referring to a layout, thus:</p>
  
  <pre><code>  layout:decorator="layouts/main"
  </code></pre>
  
  <p>I can confirm that the file IS in the jar.</p>
  
  <p>/login is defined thusly:</p>
  
  <pre><code>@Override
  public void addViewControllers(ViewControllerRegistry registry) {
      registry.addViewController("/login").setViewName("/login");
      registry.addViewController("/").setViewName("/login");
  }
  </code></pre>
  
  <p>and I have spring security configured as:</p>
  
  <pre><code>@Configuration
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
  @Override
  public void configure(WebSecurity security) {
      security.ignoring().antMatchers("/assets/**");
  }
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http
              .csrf().disable();
      http
              .authorizeRequests()
              .antMatchers("/").permitAll()
              .anyRequest().authenticated();
      http
              .formLogin()
              .loginPage("/login")
              .defaultSuccessUrl("/home")
              .failureUrl("/login?error")
              .permitAll()
              .and()
              .logout()
              .invalidateHttpSession(true)
              .logoutSuccessUrl("/login?logout")
              .permitAll();
  }
  }
  </code></pre>
  
  <p>I think that's all that might be relevant to this issue...</p>
  
  <p>I have seen <a href="https://github.com/spring-projects/spring-boot/issues/112" rel="noreferrer">https://github.com/spring-projects/spring-boot/issues/112</a> and <a href="https://stackoverflow.com/questions/22884299/proper-location-of-thymeleaf-views-for-spring">Proper location of Thymeleaf views for Spring</a> (amongst others). These resources notwithstanding, I have not been successful at getting template resolution working.</p>
  
  <p>Any suggestions gratefully recieved.</p>
  
  <p>To have come so far with Spring Boot yet to have stumbled at the last hurdle (near-final deployment) is vexatious.</p>