Spring - Cannot resolve MVC "view" thymeleaf
Asked Answered
T

10

8

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

Teodoor answered 31/1, 2020 at 10:27 Comment(0)
M
12

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>
Milky answered 7/3, 2020 at 3:42 Comment(0)
B
7

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

Ba answered 12/8, 2021 at 11:52 Comment(0)
T
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:)

Teodoor answered 31/1, 2020 at 10:46 Comment(0)
P
2

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.

Pelfrey answered 31/10, 2022 at 18:5 Comment(0)
R
1

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

Error was fixed after changing the project location.

Resupine answered 2/11, 2022 at 5:46 Comment(1)
This was the problem for me, thanks sir!Pinafore
C
1

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.

Cordeiro answered 21/8, 2023 at 11:4 Comment(0)
H
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.

Hedvige answered 10/2, 2021 at 9:11 Comment(0)
T
0

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

Tuttifrutti answered 22/5, 2022 at 13:7 Comment(0)
T
0

I previously added dependency

<!-- Thymeleaf -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>3.1.4</version>
    </dependency>

It doesn't work, even if I reload the Maven project.

Then I added <version>3.1.4</version> to reload again, it works!

Thesaurus answered 12/10, 2023 at 23:58 Comment(0)
M
0

I just encountered the same problem, but I managed to resolve it.

I simply copied the following code snippet exists in pom.xml:

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

and modified artifactId to spring-boot-starter-thymeleaf,then, I faced the same problem.

In my case, I removed the scope element and reloaded the configuration. It seems to be working fine for now.

Metaphrase answered 20/12, 2023 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.