title: Spring Boot returns string and not the view
body: <p>Currently I'm trying to learn Spring Boot and therefore thought it would be good to write a web-application with Spring Boot Web MVC. I got stuck on a problem and have not found a solution or anything on Google which helped.  I hope someone here could help me.</p>
  
  <p>Goal of the project is to build a web application with Spring Boot, Thymeleaf, Bootstrap and Hibernate, all with the newest version. I've used several tutorials but there are some things which are confusing me.</p>
  
  <p>I coded the views with Thymeleafs layout-dialect, but when I deploy the project on my local Tomcat and browse the index page I just get a String with "index" and not an html-file. I don't know where to look for the problem. I assume the way I try to integrate the layout-dialect or the way I try to return the view is wrong. I hope someone has an idea.</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>package de.rune.flying.flying.web.controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.servlet.ModelAndView;
  
  @Controller
  public class UserController {
  
      @GetMapping ( "/" )
      public ModelAndView main ( Model model ) {
  
          ModelAndView modelAndView = new ModelAndView ( );
          modelAndView.setViewName ( "index" );
          return modelAndView;
      }
  
  }
  </code></pre>
  
  <p>I've already tried another method (see below) but it didn't changed anything.</p>
  
  <p><strong>Other kind of method:</strong></p>
  
  <pre><code>        @GetMapping ( "/" )
          public String main ( Model model ) {
              return "index.html";
          }
  </code></pre>
  
  <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&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;2.1.7.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;groupId&gt;de.rune.flying&lt;/groupId&gt;
      &lt;artifactId&gt;flying&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;name&gt;flying&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;bootstrap.version&gt;4.3.1&lt;/bootstrap.version&gt;
          &lt;thymeleaf.dialect.version&gt;2.4.1&lt;/thymeleaf.dialect.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;!-- web mvc --&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;!-- thymeleaf --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;nz.net.ultraq.thymeleaf&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf-layout-dialect&lt;/artifactId&gt;
              &lt;version&gt;${thymeleaf.dialect.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- test --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!-- dev tools --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!-- optional --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
              &lt;version&gt;${bootstrap.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;flying&lt;/finalName&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;configuration&gt;
                      &lt;addResources&gt;true&lt;/addResources&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.22.0&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>layout.html:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="de"
        xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
        xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
      &lt;title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE"&gt;Layout&lt;/title&gt;
  
      &lt;link rel="stylesheet" th:href="@{webjars/bootstrap/4.3.1/css/bootstrap.min.css}"/&gt;
      &lt;link rel="stylesheet" th:href="@{/static/css/main.css}"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;header&gt;
          MY Header
      &lt;/header&gt;
      &lt;section layout:fragment="content"&gt;
          &lt;p&gt;Content goes here&lt;/p&gt;
      &lt;/section&gt;
  
      &lt;footer&gt;
          &lt;p&gt;My footer&lt;/p&gt;
          &lt;p layout:fragment="footer"&gt;Footer goes here&lt;/p&gt;
      &lt;/footer&gt;
  
      &lt;script type="text/javascript" th:src="@{webjars/bootstrap/4.3.1/js/bootstrap.min.js}"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="de"
        xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
        xmlns:th="http://www.thymeleaf.org"
      layout:decorate="~{layouts/layout.html}"&gt;
  &lt;head&gt;
      &lt;title&gt;Index title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;section layout:fragment="content"&gt;
          &lt;p&gt;Index content&lt;/p&gt;
      &lt;/section&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Let me know if some informations are missing, then I will upload them and thanks for help</p>
  
  <p><strong>edited:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/o1fvE.jpg" rel="nofollow noreferrer">project structure</a></p>
  
  <p><a href="https://i.stack.imgur.com/lR7PX.jpg" rel="nofollow noreferrer">Screenshot of resulted view</a></p>
  
  <p>When I inspect the source code of the view in my browser I just see the text "index", so it seems like he just returns the string and can't find a view with the name.</p>