5.중간메모

복습 겸 다시 프로젝트 생성해서 만들어보다가 몇가지 간략히 정리

1. springboot에서 html파일을 templates에서 읽도록 하기

템플릿 엔진과 관련된 의존성을 추가하면 자동으로 /recourses/templates 아래에서 템플릿 파일을 찾도록 하는거 같은데 원래 기본 경로는 /recourses/static 이다.

따라서 별다른 설정을 하지 않고 html 파일을 templates 폴더 밑에 놓고 찾으려고 하면 당연히 404 에러를 볼수 밖에 없다.

html 파일을 templates 아래에 관리하고 싶다면 몇가지 작업을 해야하는데

우선 스프링부트에서 WebMVC 설정을 유지하면서 기능을 확장하기 위해 WebMvcConfigurerimplements 하고 addResourceHandlers 를 오버라이드하여 아래와 같이 작성한다.

1
2
3
4
5
6
7
8
9
10
11
12
@RequiredArgsConstructor
@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/templates/")
.setCacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES));
}
}

2. application.properties -> application.yml 변환

가독성 측면에서 yaml 파일이 더 좋아보여서 기존 내용을 변환해서 쓰려다보니 naver oauth2 설정을 하면 오류가 발생한다.

redirect-uri: '{baseUrl}/{action}/oauth2/code/{registrationId}'

yaml 에서는 / (슬러시)를 그대로 쓰면 파싱 에러가 난다. 따옴표나 작은 따옴표로 감싸주면 된다.

Author

Jaeyong Yoo

Posted on

2021-04-25

Updated on

2023-06-10

Licensed under

댓글