title: Deployment of resources on embedded Tomcat server using Spring Boot
body: <p>I have a project where data from several sources are being processed into some data structures. After the program is done building these structures, I want it to set up a server that enables users to fine-tune these structures manually. I decided that Spring MVC on an embedded Tomcat server set up using Spring Boot is just what I need.</p>
  
  <p>I want to use Thymeleaf as view technology, and therefore did</p>
  
  <pre><code>@Configuration
  @ComponentScan
  @EnableAutoConfiguration
  public class Main {
  
      public static void main(String... args) throws Exception {
          // Lots of initialization ...
  
          SpringApplication.run(Main.class, args);
      }
  
      @Bean
      public ServletContextTemplateResolver templateResolver() {
          ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
          resolver.setPrefix("/resources/views/");
          resolver.setSuffix(".html");
          resolver.setTemplateMode("HTML5");
          resolver.setCacheable(false);
          return resolver;
  
      }
  
      public SpringTemplateEngine templateEngine() {
          SpringTemplateEngine engine = new SpringTemplateEngine();
          engine.setTemplateResolver(templateResolver());
          return engine;
      }
  
      @Bean
      public ViewResolver viewResolver() {
          ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
          viewResolver.setTemplateEngine(templateEngine());
          viewResolver.setOrder(1);
          viewResolver.setViewNames(new String[]{"*"});
          viewResolver.setCache(false);
          return viewResolver;
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Controller
  public class WebController {
      @RequestMapping(value="/greeting", method=RequestMethod.GET)
      public String greeting() {
          return "greeting";
      }
  }
  </code></pre>
  
  <p>But even though there is a view file at <code>/resources/views/greeting.html</code>, the server's reply to the URL <code>http://localhost:8080/greeting</code> is</p>
  
  <pre><code>org.thymeleaf.exceptions.TemplateInputException: Error resolving template "greeting", template might not exist or might not be accessible by any of the configured Template Resolvers
  </code></pre>
  
  <p>After stepping through the code in a debugger it appears that at some point, <code>ServletContext</code>, which is supposed to return the view file as a stream, looks in a temporary folder like</p>
  
  <pre><code>C:\Users\Michael\AppData\Local\Temp\tomcat-docbase.971027024999448548.8080
  </code></pre>
  
  <p>which is empty.</p>
  
  <p>Now I get that I need to either</p>
  
  <ol>
  <li><p>Have the resources deployed to the temporary folder when the server starts up</p></li>
  <li><p>Have the server operate in the directory where the resources already are</p></li>
  </ol>
  
  <p>My problem just is that I don't know how to do either, or which approach is the best. Something tells me that 1 is the better wisdom, but any suggestion is welcome.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Ok, I ended up with something that seems to work. While Joe's answer definitely helped me get on the way, it also appears that I had to change my Maven configuration in a way that puzzles me.</p>
  
  <p>After putting the template <code>greeting.html</code> into <code>/resources/templates/greeting.html</code> and adding <code>resources</code> to the build path, I got the error</p>
  
  <pre><code>javax.servlet.ServletException: Circular view path [greeting]: would dispatch back to the current handler URL [/word/greeting] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
  </code></pre>
  
  <p>In other words, Thymeleaf seemed to not be properly configured. After some fiddling I ended up changing the version of <code>spring-boot-starter-parent</code> in <code>pom.xml</code> from <code>0.5.0.BUILD-SNAPSHOT</code> to <code>0.5.0.M6</code>:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;!--&lt;version&gt;0.5.0.BUILD-SNAPSHOT&lt;/version&gt;--&gt;
      &lt;version&gt;0.5.0.M6&lt;/version&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>and removing the version tag from the Thymeleaf dependency</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;!-- ... --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
          &lt;artifactId&gt;thymeleaf-spring3&lt;/artifactId&gt;
          &lt;!--&lt;version&gt;${thymeleaf-spring3-version}&lt;/version&gt;--&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>After this, it worked.</p>
  
  <p>Can someone please explain why I needed to change the version of <code>spring-boot-starter-parent</code> to be able to remove the version tag from <code>thymeleaf-spring3</code>, and why that was necessary?</p>