오곡(Ogok)
error-thymeleaf 적용 시 whitelabel error page가 나와요.
주다애
2024. 12. 27. 10:47
상황 : spring 프로젝트 시에 thymeleaf로 화면을 구성하고 서버를 올렸다.
그리고 localhost:8080/{내 html 파일 이름}.html을 하니 whitelabel error page를 마주하게 되었다.
해결
일단 확인할 것은 다음과 같다.
build.gradle
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
applicaton.yml
# Thymeleaf 설정
spring:
thymeleaf:
prefix: classpath:/templates/
suffix: .html
cache: false
두 개 모두 적절히 설정이 되었다면
다음을 확인하자
MvcConfiguration.class
@Configuration
public class MvcConfiguration implements WebMvcConfigurer {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/templates/", "classpath:/static/")
.setCacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES));
}
}
위의 설정 클래스를 만들어주어야 하는 이유는 다음과 같다.
- 설정하기 전에는 static 폴더의 html 파일을 불러온다.
- 그래서 templates 폴더의 html 파일을 불러오게 만들어야 한다.(addResourceLocations("classPath:/templates/")
이렇게 해주면 서버가 올라가고 정상적으로 html 파일에 접근하게 되어 화면이 나오게 된다!
참고 자료
[Spring Boot] thymeleaf 사용하기 (1) - thymeleaf 초기 설정하기 | templetes 폴더에서 정적 파일 불러오기 |
[Spring] thymeleaf 사용하기 (1) thymeleaf 기초 설정 - templetes 폴더에서 정적 파일 불러오기 -View Mapping Controller 생성 Thymeleaf 란? - spring 기반 웹 애플리케이션의 view에서 html, xml, javascript, css, text 처리 후
devzzi.tistory.com