정적 페이지 반환(static)
implementation 'org.springframework.boot:spring-boot-starter-web'
기본 Welcome page
- 위 의존성 추가하고 resource/static 아래에 index.html 파일 위치시키면 localhost:8080으로 접속 시 자동으로 해당 페이지를 렌더링 해줌
Controller URI 에 따라 html 페이지 반환
[ StackOverflow ] Serve static html files omitting the .html extension in the url

@Configuration public class ServletConfig implements WebMvcConfigurer { @Bean public InternalResourceViewResolver internalResourceViewResolver() { InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver(); internalResourceViewResolver.setPrefix("docs/"); // docs 폴더가 ResourceLocation 경로 안에 포함되어야 함 internalResourceViewResolver.setSuffix(".html"); return internalResourceViewResolver; } @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/docs").setViewName("index"); } }
docs/
경로가ResourceLocation
안에 포함되어야 함(ResourceLocation + “/docs/” + pageName.html
)- 만약 static file의 serving이 configure가 됐다면 위의 문제는 고려하지 않아도 됨.
WebMvcConfigurer
의addResourceHandlers
확인해보면 됨
@Controller @RequestMapping("/docs") public class StaticContentController { @GetMapping public String restDocs() { return "index"; } }
동적 페이지(template)
resources/templates
하위에 home.html 작성
- 해당 home.html을 반환하는 컨트롤러 작성
@Controller @RequestMapping("/docs") public class StaticContentController { @GetMapping public String restDocs() { return "index"; } }