HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
[New] 타일러팀
[New] 타일러팀
/
🎾
김수미
/SpringBoot 강의노트/
DAY1 : Spring 기초

DAY1 : Spring 기초

Created
Apr 7, 2022 02:28 AM
Tags
📎
Build Tool 선택하기
Build Tool이 하는 일
  • 필요한 라이브러리를 다운 받고 classpath에 추가하는 일
  • 소스 코드를 컴파일 하는 일
  • 테스트를 실행하는 일
  • 컴파일 된 코드를 packing 하는 일 (jar, war, zip 등의 파일로)
  • packing된 파일을 주로 artifacts 라고 부르고, 이를 서버 또는 repository에 배포하는 일

Build Script
  • Build Tool 에게 어떠한 작업을 시킬 것임을 기술해둔 파일을 의미한다.
  • Build Tool 에 따라 Build Script 형태가 다르다.
    • 예) Maven은 pom.xml 파일로 작성 / Gradle은 Kotlin, Groovy 등을 이용하여 작성
    •  
📎
Maven 에 대해서
Maven 이란?
  • 빌드 도구로써 주로 자바 기반의 프로젝트에서 많이 사용된다.
  • XML 기반으로 설정 모델을 제공하고 pom.xml 파일로 작성할 수 있다.
  • POM = Project Object Model

Maven을 사용하는 이유
  • Archetypes 라는 프로젝트 템플릿을 제공하기 때문에 매번 같은 설정을 반복하지 않아도 된다.
  • 프로젝트에서 사용하는 외부 라이브러리인 Dependency를 관리해준다.
  • 플러그인과 외부 라이브러리를 분리하여 관리한다.
  • Dependency를 다운받는 Repository는 로컬이 될 수도 있고, Maven Central 같은 공개된 Repository가 될 수도 있다.
 
 
📎
Spring 기반 어플리케이션 프로젝트 만들기
Manual Setup
  • Maven / Gradle 로 프로젝트를 만들고 pom.xml 이나 build.gradle을 직접 수정하는 방법
Spring Boot
Getting Started
Spring Boot helps you to create stand-alone, production-grade Spring-based applications that you can run. We take an opinionated view of the Spring platform and third-party libraries, so that you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Getting Started
https://docs.spring.io/spring-boot/docs/2.5.0/reference/html/getting-started.html#getting-started
  • Spring Boot CLI를 이용하는 방법
    • Getting Started
      Spring Boot helps you to create stand-alone, production-grade Spring-based applications that you can run. We take an opinionated view of the Spring platform and third-party libraries, so that you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
      Getting Started
      https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started.html#getting-%20started.installing.cli
      Spring Boot CLI
      Once you have installed the CLI, you can run it by typing spring and pressing Enter at the command line. If you run spring without any arguments, a help screen is displayed, as follows: $ spring usage: spring [--help] [--version] [ ] Available commands are: run [options] [--] [args] Run a spring groovy script _...
      Spring Boot CLI
      https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html
  • IntelliJ의 Spring Initializer를 이용하는 방법

Spring Boot의 역할
  • 컴퓨터를 부팅한다는 말처럼 시스템을 사용 가능한 상태로 만드는 역할을 해준다.
    • SpringApplication을 통한 손쉬운 실행
    • Auto Configuration
    • 쉬운 외부 환경 설정 : Properties, YAML, Command line 설정 등
    • 프로파일을 통한 실행환경 관리
    • Packaging Executable Jar
    • Developer Tools
 
📎
Domain Driven Design
Spring Framework의 핵심 개념
Core Technologies
There are pros and cons for considering validation as business logic, and Spring offers a design for validation (and data binding) that does not exclude either one of them. Specifically, validation should not be tied to the web tier and should be easy to localize, and it should be possible to plug in any available validator.
Core Technologies
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html
  • Spring Core Technologies에는 아래와 같은 기술들이 있다.
    • Spring IoC 컨테이너 그리고 Beans
    • 리소스 핸들링(Resource와 ResourceLoader) 벨리데이션 / 데이터바인딩
    • 타입 변환 스프링 expression 언어
    • AOP / Null-safety
    • 데이터 버퍼와 코덱 / 로깅
사람들이 자주 이야기하는 ‘로깅’이 뭘까?

Domain Driven Design
  • 스프링 기초과정을 진행해가면서 주문관리 애플리케이션을 만들어 볼 것
  • 예제코드를 작성하면서 몇가지 용어들이 등장하므로, 용어정리를 먼저 하고 가자!
  • Entity
    • 엔터티는 고유한 식별자를 가지며, 시간에 흐름에 따라 지속적으로 상태가 변경되는 객체이다.
      • →  ‘주문’ = Entity : 고유 식별자를 가지며 상태가 변한다(배송중, 배송완료  등).
        → ‘주문’ = Entity : 고유 식별자를 가지며 상태가 변한다(배송중, 배송완료 등).
  • Value Object(값 객체)
    • 💡
      불변객체는 내부 상태가 시간이 흘러도 고정이고, 변경될 수 없기 때문에 여러 쓰레드에서 안전하게 공유될 수 있다.
    • 각 속성이 개별적으로 변화하지 않고, 값 그 자체로 고유한 불변 객체이다.
    • 주로 Entity 들이 value object 들을 속성으로 가진다.
    • 위의 예시에서는 주문자, 배송지가 Value Object에 해당 (값이 변화하지 않는다)
    • Java14에서 소개된 Record 키워드를 이용 하면 VO를 쉽게 작성할 수 있다.
 
📎
Dependency 의존성
의존성이란 무엇인가?
  • 스프링의 IoC(Inversion Of Control)컨테이너 혹은 DI (Dependency Injection)을 다루기 앞서, 먼저 의존성에 대해서 살펴볼 필요가 있다.
  • 어떤 객체가 협력하기 위해 다른 객체를 필요로 할 때, 두 객체 사이의 의존성이 존재하게 된다.
  • 의존성은 실행 시점(compile time)과 구현 시점(runtime)에 서로 다른 의미를 가진다.
  • 컴파일타임 의존성
    • 코드를 작성하는 시점에 발생하는 의존성이며, 클래스 사이의 의존성을 의미한다.
  • 런타임 의존성
    • 애플리케이션이 실행되는 시점에 발생하는 의존성이며, 객체 사이의 의존성을 의미한다.

결합도란 무엇인가?
  • 결합도란 하나의 객체가 변경이 일어날 때에 관계를 맺고 있는 다른 객체에게 변화를 요구하는 정도
  • 바람직한 의존성 : 느슨한 결합도 / 약한 결합도
    • 재사용 및 설계의 수정이 용이한 구조이기 때문이다.
  • 바람직하지 못한 의존성 : 단단한 결합도 / 강한 결합도
  • 컴파일타임 의존성(클래스 간 의존성)보다는 런타임 의존성(객체간 의존성)이 더 느슨한 결합도를 갖는다.
    • → Order 클래스가 FixedAmountVoucher를 직접 참조하는 컴파일 타임 의존성
      → Order 클래스가 FixedAmountVoucher를 직접 참조하는 컴파일 타임 의존성
      → Order 클래스가 인터페이스를 통해 Voucher 객체를 사용하는 런타임 의존성(느슨한 결합)
      → Order 클래스가 인터페이스를 통해 Voucher 객체를 사용하는 런타임 의존성(느슨한 결합)
    • Runtime에 객체를 생성해서 전달해주므로 runtime dependency
    • Order 입장에서는 코드를 수정하지 않아도 FixedAmountVoucher를 받아 사용할 수 있다.