본문 바로가기

Framework/Spring

정적 컨텐츠 (Static Content)

웹을 개발한다는 것은 크게 3가지 방법이 있다. 정적 컨텐츠, MVC와 템플릿 엔진, 그리고 API이다.

 

스프링 부트는 정적 컨텐츠(static content)를 자동으로 제공한다. 정적 컨텐츠는 서버에서 무언가 하는 것 없이 그냥 파일을 그대로 웹브라우저에 내려주는 것이다.

 

 

웹브라우저에서 localhost:8080/hello-static.html을 입력하면, 내장 톰캣 서버가 우선 요청을 받는다. 그리고 톰캣은 스프링에게 이것을 넘긴다. 스프링은 먼저 컨트롤러 쪽에서 hello-static이라는 컨트롤러가 있는지 찾는다. 그런데 hello-static과 관련되어 매핑된 컨트롤러가 없다. 그러면 스프링 부트는 내부의 resources에 있는 static 폴더 안의 hello-static.html을 찾는다.

 

 

hello-static.html이 있으니 이것을 반환한다.

 

우리가 원하는 파일을 그냥 넣으면 된다. 그러면 정적 파일은 '그대로' 반환이 된다. 대신 여기에는 어떤 프로그램을 넣을 수 없다.

 

 

 

 

 

[참고자료]

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

'Framework > Spring' 카테고리의 다른 글

API  (0) 2022.11.29
MVC와 템플릿 엔진  (0) 2022.11.29
스프링 부트 (Spring Boot) 동작 환경  (0) 2022.11.28