6

I got a simple HomeController.class:

package com.example.tacos;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

    @GetMapping("/")
    public String home() {
        return "home";
    }
}

Also I got a template called home.html

<!DOCTYPE HTML>
    <head>
    <title>Getting Started: Serving Web Content</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <p>Hey</p>
    </body>
</html>

Anyway I'm getting 404 in the browser and IDE's telling me Cannot resolve MVC "view" as you can see on the screen

Folder Structure: Folder Structure

Browser: Browser

Community
  • 1
  • 1
Vadim Sheremetov
  • 523
  • 1
  • 4
  • 14

8 Answers8

10

Hi I had the same issue and I fixed it by delete the version of Thymeleaf so the pom file will be like :

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
gumira
  • 116
  • 4
6

To solve this problem you should add path to web app package into Web Resource Directories.

  1. Alt + Ctrl + Shift + S ("Project Structure" window opens)
  2. Go to tab "Facets"
  3. Then click tab "Web"
  4. Add new package to "Web Resource Directories"

enter image description here

Rain
  • 3,416
  • 3
  • 24
  • 40
cheladon
  • 121
  • 1
  • 5
2

The problem was that in pom.xml I had this:

<dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>3.0.11.RELEASE</version>
</dependency>

instead of this:

 <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>2.2.2.RELEASE</version>
    </dependency>

Just started learning spring and don`t get dependencies well enough yet:)

Vadim Sheremetov
  • 523
  • 1
  • 4
  • 14
1

I had the same issue in the project as:

"Cannot resolve MVC view"

and the cause of it was misspelling with naming of the folder.

The structure was:

   |   |-- resources
   |   |   |-- template
   |   |   |   |-- customer.html
   |   |   |   |-- customerForm.html
   |   |   |   |-- customers.html
   |   |   |   |-- index.html

I needed to use the name as templates of the folder, but I had template.

Maybe, it'd be helpful for someone also.

invzbl3
  • 5,872
  • 9
  • 36
  • 76
1

I found that my current project was created in another previous project.

Error was fixed after changing the project location.

artimarti
  • 11
  • 1
0

I had the correct entry suggested by gumira in my pom.xml and I was still getting the error.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

I had to fix Maven Plugin not found in IntelliJ IDE instead and rebuild.

Bolek
  • 51
  • 3
0

I change the version of tomcat from 10.0.20 to 8.5.78 and sovle it.

Ando
  • 1
0

To anyone who use Gradle, I had this in my build.gradle file;

implementation 'org.thymeleaf:thymeleaf:3.1.2.RELEASE'

I have changed it to

implementation('org.springframework.boot:spring-boot-starter-thymeleaf:3.0.4')

and it worked for me.

ubovic
  • 1
  • 3