프로젝트 환경 설정
김영한님의 스프링부트 강의를 듣고 작성했습니다.
[무료] 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 - 인프런 | 강의
스프링 입문자가 예제를 만들어가면서 스프링 웹 애플리케이션 개발 전반을 빠르게 학습할 수 있습니다., 스프링 학습 첫 길잡이! 개발 공부의 길을 잃지 않도록 도와드립니다. 📣 확인해주세
www.inflearn.com
초기화
스프링 프로젝트의 초기화는 스프링 부트 스타터 패키지를 사용했고, Gradle를 사용했다
디펜던시는 Spring Web, Thymeleaf를 추가했다.
Gradle 빌드 및 라이브러리
초기화후 IntelliJ에서 오픈하면 빌드가 진행되며 필요한 라이브러리들을 설치한다. 이 후에 라이브러리 목록들을 보면
추가한 의존관계는 두 개만 추가했음에도 불구하고 여러 라이브러리들을 함께 설치하는 것들을 볼 수 있는데
이는 추가한 라이브러리가 필요로하는 의존 라이브러리들을 함께 설치하기 때문이다.
설치된 주요 라이브러리는 다음과 같다.
스프링 부트 라이브러리
- spring-boot-starter-web
- spring-boot-starter-tomcat: 톰캣(웹서버)
- spring-webmvc: 스프링 웹 MVC
- spring-boot-starter-thymeleaf: 타임리프 템플릿 엔진(View)
- spring-boot-starter(공통): 스프링 부트 + 스프링 코어 + 로깅
- spring-boot
- spring-core
- spring-boot
- spring-boot-starter-loggin
- logback, slf4j
테스트 라이브러리
- spring-boot-starter-test
- junit: 테스트 프레임워크
- mockito: 목 라이브러리
- assertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리
- spring-test: 스프링 통합 테스트 지원
* 스프링 부트가 지원하는 Welcome page 기능
static폴더에 index.html파일을 올려두면 해당 홈페이지의 '/'에 접속했을 때 index.html 파일을 넘겨준다.
자세한 내용은 하단 참조
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
thymeleaf 템플릿 엔진
템플릿 엔진이란 가지고 있는 데이터와 특정한 템플릿을 이용해 문서를 만들어내는 소프트웨어다.
thymeleaf는 템플릿 엔진중 한 종류로써 thymeleaf의 템플릿과 제공된 데이터를 이용해 원하는 문서를 만들어낼 수 있도록 도와준다.
thymeleaf 동작방식
HelloController에서 요청을 받으면 해당하는 템플릿을 data와 함께(model(data:hello!)) 문자열로 리턴해주게 된다.
그러면 viewResolver가 문자열에 해당하는 파일을 찾아서 문서를 만들어내는 방식으로 진행된다.
기본적으로 viewResolver는 'resources:templates/{ViewName}+.html'를 맵핑한다.
thymeleaf 공식 사이트: https://www.thymeleaf.org/
스프링 공식 튜토리얼: https://spring.io/guides/gs/serving-web-content/
스프링 부트 메뉴얼: https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-template-engines
빌드하고 실행하기
$ cd {스프링_프로젝트_폴더}
$ ./gradlew build
$ cd build/libs
$ java -jar hello-spring-0.0.1-SNAPSHOT.jar
실행 확인
References
Thymeleaf - Wikipedia
Thymeleaf is a Java XML/XHTML/HTML5 template engine that can work both in web (servlet-based) and non-web environments. It is better suited for serving XHTML/HTML5 at the view layer of MVC-based web applications, but it can process any XML file even in off
en.wikipedia.org
https://en.wikipedia.org/wiki/Template_processor
Template processor - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Software designed to combine templates with a data model to produce result documents A diagram illustrating all of the basic elements and processing flow of a template engine. A templa
en.wikipedia.org
[무료] 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 - 인프런 | 강의
스프링 입문자가 예제를 만들어가면서 스프링 웹 애플리케이션 개발 전반을 빠르게 학습할 수 있습니다., 스프링 학습 첫 길잡이! 개발 공부의 길을 잃지 않도록 도와드립니다. 📣 확인해주세
www.inflearn.com