정적컨텐츠란 welcome page를 만들어서 전달했던 것 처럼 html파일 자체를 그대로 웹브라우저에 전달해주는 방식이다.
Spring Boot에서는 정적컨텐츠 기능을 자동으로 제공한다.
https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-static-content
Spring Boot Features
Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and Servlet-based web applications. It occurs as part of closing the application context and is performed in the earliest
docs.spring.io
실제로 어떻게 동작하는지 IDE에서 테스트 할 수 있는 실습과정이다.
브라우저에 보여주고 싶은 원하는 html파일을 resources/static 경로에 생성한다.
테스트용 html 소스를 간단히 작성했다.
(파일명 : hello-static.html)
<!DOCTYPE HTML>
<html>
<head>
<title>jin2rang's static content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
jin2rang 정적 컨텐츠 파일 입니다.
</body>
</html>
프로젝트를 실행(run)시킨 후에 해당 파일이 브라우저에 잘 보이는지 확인한다.
현재 서버 포트가 8080이므로, localhost:8080/hello-static.html을 브라우저에서 요청한다.
그러면, 생성한 html파일을 볼 수 있다.
이때, 꼭 ' 파일명.html '로 요청해야한다.
이렇게 정적컨텐츠는 resources/static폴더에서 요청한 html파일을 가져와 브라우저에 보여준다.
대신 프로그래밍을 할 수 없고 html파일화면 그 자체만 볼 수 있다.

동작원리를 그림으로 살펴보면, 다음과 같다.
'개발 이모저모 > Spring' 카테고리의 다른 글
HandlerMethod란? (0) | 2025.01.16 |
---|---|
Spring Boot - 웹개발 기초 - ② MVC란? (0) | 2022.11.09 |
Spring Boot 기초 - 라이브러리 살펴보기 (0) | 2022.06.27 |
Spring Boot - thymeleaf ( 템플릿 엔진 ) (0) | 2022.06.25 |
Spring Boot - Welcome Page 만들기 (0) | 2022.06.25 |