인프런 커뮤니티 질문&답변

hbs0606님의 프로필 이미지

작성한 질문수

실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발

View 환경 설정

thymeleaf 의 경로를 못찾는다고 나오네요

20.09.07 23:19 작성

·

39K

3

 indx.html을  /src/main/resourcee/static/index.html을 넣어도 못찾네요

hello예제에서는 "template might not exist or might not be accessible by any of the configured Template Resolvers" 

로 나오네요 경로가 차이가 있는건지 모르겠습니다.

아래는 grandle 설정입니다 

어떤 문제가 있는건지 모르겠습니다.

plugins {
id 'org.springframework.boot' version '2.1.16.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}

group = 'jpabook'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

답변 6

5

김영한님의 프로필 이미지
김영한
지식공유자

2020. 09. 10. 19:28

프로젝트를 새로 만들어서 잘 해결되었다고 하시네요^^

다른분들도 참고해주세요.

4

HyeonIL Choi님의 프로필 이미지

2022. 06. 06. 15:49

혹시나 저처럼 실수하는 분이 있을까봐 추가 댓글을 답니다

저는 hello.html 템플릿 파일은 잘 만들고나서, 컨트롤러에서

return 'hello'; 가 아닌 return 'hello!'; 라고 했는데요 

(그냥 문자열 리턴하는거니 그게 그거겠거니 라고 생각)

저 return에 명시되는 문자열이 template 파일 이름과 동일해야 하네요.

그냥 @GetMapping decorator에 hello 라고 경로를 지정하면 알아서 hello.html 템플릿이 사용되는줄 알았는데 그게 아니었어요...

참고하시길 바래요

* 강의에서도 바로 뒤이어서 내용이 나오네요

skageec님의 프로필 이미지

2022. 07. 10. 12:55

동일한 문제였는데 덕분에 해결했습니다. 감사합니다,

John Choi님의 프로필 이미지

2022. 12. 06. 13:18

저도 덕분에 해결했습니다. 감사합니다.

mandarinnn2님의 프로필 이미지

2023. 09. 05. 17:01

덕분에 해결했어요 감사합니다.

1

김영한님의 프로필 이미지
김영한
지식공유자

2020. 09. 08. 22:10

안녕하세요. hbs0606님^^

주신 코드를 확인해보니

application.properteis가 잘못 설정되어 있었습니다.

원본

spring.thymeleaf.prefix=classpath:src/main/resources/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.thymeleaf.order=0

해당 코드를 모두 지우면 됩니다^^!

http://localhost:8080

http://localhost:8080/hello

둘다 성공하는 것을 확인했습니다.

0

김영한님의 프로필 이미지
김영한
지식공유자

2020. 09. 09. 21:04

hbs0606님

먼저 intelliJ 문제인지, 아니면 단순한 코드 문제인지로 범위롤 좁혀봅시다^^!

전체 코드를 빌드해서 IntelliJ 외부에서 실행해볼께요.

먼저 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술

강의로 가셔서 빌드하고 실행하기를 참고해주세요.

내용을 옮겨오면

mac, linux 콘솔로 이동

1. `./gradlew build`

2. `cd build/libs`

3. `java -jar hello-spring-0.0.1-SNAPSHOT.jar`

4. 실행 확인

윈도우 사용자를 위한 팁

* 콘솔로 이동 -> 명령 프롬프트(cmd)로 이동

* `./gradlew` -> `gradlew.bat`를 실행하면 됩니다.

* 명령 프롬프트에서 `gradlew.bat`를 실행하려면 `gradlew`하고 엔터를 치면 됩니다.

* `gradlew build`

* 폴더 목록 확인`ls` -> `dir`

* 윈도우에서 Git bash 터미널 사용하기

* 링크: https://www.inflearn.com/questions/53961

방금 내용을 참고하셔서

java -jar hello-spring-0.0.1-SNAPSHOT.jar 라고 실행해보세요.

그런 다음에 다음 URL을 호출해보시겠어요?

http://localhost:8080

http://localhost:8080/hello

만약 잘 동작하면 소스에는 문제가 없고, IntelliJ에만 문제가 있는 상황입니다.

이런 경우 IntelliJ를 완전히 삭제하고 다시 설치하고, 프로젝트도 처음부터 다시 세팅해주세요.

그럼 결과 기다릴께요^^

Taehyun Kim님의 프로필 이미지

2022. 07. 05. 05:30

안녕하세요 영한님. 인텔리제이 외부에서 빌드 후 실행 시 localhost:8080은 잘 되는데 localhost:8080/hello 는 whitelabel error가 뜨면 인텔리제이가 아닌 코드에 문제가 있는걸까요? 

김영한님의 프로필 이미지
김영한
지식공유자

2022. 07. 10. 12:33

안녕하세요. Taehyun Kim님

네 코드에 문제가 있는 것 같아요.

0

hbs0606님의 프로필 이미지
hbs0606
질문자

2020. 09. 09. 09:08

application.properteis 는  적용이 안되엇 넣은 부분 입니다.

제가 인텔리j를 많이 사용해 보지 않아서 그러는데 인텔리J(2019.2버전) 설정에서 변경해야 하는거나

스프링부트에서 경로를 못찾는건 아닐가 하는 생각이 드는데요

아래는 제 쪽에서 발생하는 에러 코드 입니다.

2020-09-09 09:02:56.332 ERROR 9508 --- [nio-8080-exec-2] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-2] Exception processing template "hello": Error resolving template [hello], template might not exist or might not be accessible by any of the configured Template Resolvers

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [hello], 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.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]

0

김영한님의 프로필 이미지
김영한
지식공유자

2020. 09. 08. 00:07

안녕하세요. hbs0606님

thymeleaf 파일은 src/main/resources/templates/hello.html 에 두시면 됩니다^^

만약에 그래도 동작하지 않으면 전체 프로젝트를 압축해서 올려주세요.

어떤 내용이 동작하지 않는지 자세히 설명 부탁드립니다.

hbs0606님의 프로필 이미지

작성한 질문수

질문하기