티스토리 뷰
상황 : 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
'오곡(Ogok)' 카테고리의 다른 글
| error-css파일 net::ERR_ABORTED 404 (Not Found) (0) | 2024.12.28 |
|---|
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Spring
- ddl-auto
- Thymeleaf
- 오블완
- 백준
- @Spring
- 일급컬렉션
- @ConfigurationProperties
- 자바
- springboot
- JPA
- StreamAPI
- 이진탐색
- 동등성
- uncheckedException
- null
- N+1문제
- id생성전략
- @Value
- NPE
- 티스토리챌린지
- 생성자
- upperBound
- 유효성 검사
- checkedException
- Java
- @NoArgsConstructor
- 메인메소드
- Optional
- lowerBound
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함