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

11 Answers 11

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>
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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:)

Comments

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.

Comments

1

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

Error was fixed after changing the project location.

Comments

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.

Comments

1

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!

Comments

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.

Comments

0

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

Comments

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.

Comments

0

I had all the dependencies and settings for IntelliJ. What I was missing was settings for Thymeleaf on the application.properties (or applications.yml):

application.properties

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

application.yml

spring:   
  thymeleaf:
    prefix: classpath:/templates/  
    suffix: .html 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.