Spring Boot 시작하기 - 목표
- 왜 Spring Boot인가? : Spring Boot 없이도 웹 앱과 REST API를 구현 가능한데도?
- Spring Boot의 목표는 무엇인가?
- Spring Boot 프레임워크는 어떻게 작동하는가?
- Spring Boot, Spring MVC, Spring의 비교
Spring Boot 이전의 세계
- Spring 프로젝트를 다른 도움 없이 직접 설정하는 작업은 쉬운 작업이 아님
- 많은 요소들을 직접 설정한 후에야 프로덕션 환경에서 사용 가능한(Production-Ready) 애플리케이션을 얻을 수 있음
- Spring Boot 이전의 주요 어려움 예시
pom.xml
(의존성 관리) : 필요한 모든 의존성(Dependency)과 그 버전에 대해 pom.xml
을 작성하고 관리해야 함
web.xml
(웹 앱 설정 정의) : DispatcherServlet과 같은 Spring MVC의 설정과 컴포넌트 스캔, 뷰 리졸버 등 Spring의 설정들, 그리고 데이터베이스를 위한 데이터 소스 정의 등을 직접 관리해야 함
context.xml
(Spring Bean 관리)
- 비기능 요구사항 구현 : 로깅, 오류 처리, 프로덕션 단계 제품의 모니터링 등을 수동 구현해야 함
- 위 모든 어려움이 새 프로젝트를 시작할 때마다 반복됨
- 설정 작업만 며칠씩 걸리는 것이 일반적
- 유지보수에도 오랜 시간이 소요됨
Spring Boot를 사용하여 Hello World API 빌드하기
@RestController
: 링크 노출...?
@RequestMapping([매핑하고자 하는 주소])
: URL을 특정 메소드에 매핑
- Spring Boot를 통해 개발자는 설정 등의 번거로운 작업 대신 비즈니스 로직에만 집중할 수 있음
Spring Boot의 목표 이해하기
- Spring Boot의 목표 : "Help you build PRODUCTION-READY apps QUICKLY"
- 프로덕션 환경에서 사용 가능한 애플리케이션을 빠르게 빌드할 수 있도록 돕는 것
- 빠른 빌드
- Spring Initializr : 빠른 Spring Boot 프로젝트 빌드
- Spring Boot Stater Projects : 빠른 프로젝트 의존성 정의
- Spring Boot Auto Configuration : 클래스 경로 기반 의존성에 따라 자동 설정 제공
- Spring Boot DevTools : 수동 서버 재시작 없이 애플리케이션 변경 가능
- 프로덕션 환경에서 사용 가능한 앱
- 로깅 기능 제공
- 여러 환경에 적합한 다양한 설정 제공 : DEV / QA / STAGE / PROD 환경 등을 위한 Profiles, ConfigurationProperties
- 애플리케이션 모니터링(Spring Boot Actuator) : 메모리 사용량 등 측정 항목 확인 기능 제공
Spring Boot Starter Projects
- 애플리케이션 빌드에는 다양한 프레임워크가 필요한 것이 일반적임
- REST API : Spring 프레임워크, Spring MVC 프레임워크, Tomcat, JSON 변환 등
- Unit Test 작성 : Spring Test, JUnit, Mockito 등