[Solved] template might not exist or might not be accessible by any of the configured Template Resolvers

Spring-Boot + Thymeleaf + Intellij (2019.2) 사용 중 오류.


#Error Message

2021-05-29 15:55:22.941 ERROR 25300 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers

at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]


#Situation

IntelliJ IDEA 2019.2.4

Java jdk 1.8.0_231

gradle 7.0.2

org.springframework.boot 2.5.0


#Step

1. Create Project

- Project SDK : java version "1.8.0_231"

- Type : Gradle Project

- Java Version : 8

- Dependencies 

- Developer Tools : Srping Boot DevTools

- Web : Spring Web

- Template Engines : Thymeleaf

2. Create Controller and GetMepping

package com.thymeleaf.demo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class MainController { 
    @GetMapping("/")
    public String index (Model model) { 
        return "index";
    } 
}

3. Create src/main/resources/templates/index.html

<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>Hello Thymeleaf</h1>
</body>
</html>

4. Run DemoApplication (Shift + F10)

5. http://localhost:8080/ in browser

6. Error Occurred.

Error resolving template[index] 이미지
Error resolving template[index]

#Solved (해결)

Run the application as a Gradle bootRun task. (Ctrl + F5)

Gradle - bootRun 명령으로 실행한다.


#Why?

정확한 원인을 아직 모르겠다.

위와 같은 상황에서 Intellij 가 classpath를 찾지 못하는 것 같다.

그래서 템플릿 폴더 하위에 있는 html을 찾지 못해 발생하는 내부적인 문제 아닐까?

찾게 되면 내용을 업데이트 해야 되겠다.
















댓글