본문으로 건너뛰기
김신건의 로그

[Spring] 개요: Framework, Boot, Cloud

· 수정 · 📖 약 2분 · 782자/단어 #spring #java #framework #boot
spring overview, spring framework, spring boot, spring ecosystem

정의

Spring은 Java 엔터프라이즈 표준 프레임워크 그룹. 2003년 Rod Johnson이 EJB 대안으로 시작. IoC/DI가 핵심. 현재는:

  • Spring Framework: 기본 (IoC, AOP, MVC, JDBC, Transaction)
  • Spring Boot: 자동 설정으로 즉시 실행 가능한 앱 구성
  • Spring Cloud: 마이크로서비스 지원
  • Spring Data: 데이터 접근 추상화 (JPA, MongoDB, Redis, …)
  • Spring Security: 인증·인가
  • Spring Batch: 배치 처리

신규 프로젝트는 거의 모두 Spring Boot 시작.

Spring Boot 빠른 시작

# Spring Initializr
# https://start.spring.io 또는 IDE
// build.gradle.kts
plugins {
    java
    id("org.springframework.boot") version "3.4.0"
    id("io.spring.dependency-management") version "1.1.6"
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    runtimeOnly("com.h2database:h2")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}
// MyApplication.java
package com.example.myapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}
// HelloController.java
@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring!";
    }
}
./gradlew bootRun

핵심 개념

IoC (Inversion of Control)

객체 생성/생명주기를 컨테이너가 관리. 코드가 “이 객체 줘”라고 요청, 컨테이너가 적절한 인스턴스 주입.

DI (Dependency Injection)

객체가 자기 의존성을 직접 만들지 않고 외부에서 주입받음.

@Service
public class UserService {
    private final UserRepository userRepository;

    // 생성자 주입 (권장)
    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public User findById(Long id) {
        return userRepository.findById(id).orElseThrow();
    }
}

UserService를 사용하는 코드는 UserRepository 인스턴스 어떻게 만들지 몰라도 됨.

Bean

Spring 컨테이너가 관리하는 객체. @Component, @Service, @Repository, @Controller, @RestController, @Configuration 등으로 등록.

ApplicationContext

Bean 컨테이너. 모든 Bean의 생명주기 관리, DI 수행, 이벤트 publish.

AOP

cross-cutting concern (로깅, 트랜잭션, 보안)을 모듈화. @Aspect로.

Spring Boot 자동 구성

@SpringBootApplication은 셋 합친 것:

  • @Configuration: 설정 클래스
  • @EnableAutoConfiguration: classpath 기반 자동 설정
  • @ComponentScan: 이 패키지 이하의 @Component 자동 등록

classpath에 spring-boot-starter-data-jpa가 있으면:

  • DataSource 자동 구성
  • EntityManager 자동 구성
  • 트랜잭션 매니저 자동 구성

application.properties로 세부 조정:

spring.datasource.url=jdbc:postgresql://localhost:5432/myapp
spring.datasource.username=myapp
spring.datasource.password=...
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

server.port=8080

Starter dependencies

spring-boot-starter-*로 한 줄에 필요한 lib 묶음.

Starter포함
webTomcat + Spring MVC + Jackson
webfluxReactor + Netty
data-jpaJPA + Hibernate
data-redisRedis client
securitySpring Security
validationBean Validation
actuator모니터링 endpoint
testJUnit + Mockito + AssertJ

버전 정책

버전출시지원비고
3.02022-11LTSJakarta EE 9 + Java 17
3.12023-05
3.22023-11
3.32024-05
3.42024-11현재 stable
3.52025-05LTS 후보

Java 17+, Jakarta EE namespace(jakarta.*). Spring 5.x 호환성 깨짐 → migration tool 필요.

Spring vs Spring Boot 차이

Spring FrameworkSpring Boot
출발점XML/Java config 수동자동 설정
서버별도 (Tomcat 등)내장 (embedded Tomcat)
패키징WARJAR (executable)
설정명시적convention
학습 곡선가파름부드러움

새 프로젝트는 Boot. 레거시 Spring Framework도 여전히 흔함.

Spring 생태계

Spring Boot
├── Spring Framework (core)
│   ├── Core Container (IoC, DI)
│   ├── AOP
│   ├── Spring MVC / WebFlux
│   ├── JDBC, ORM, Transaction
│   └── Test
├── Spring Data
│   ├── JPA
│   ├── MongoDB
│   ├── Redis
│   ├── Elasticsearch
│   └── R2DBC (reactive)
├── Spring Security
│   ├── Authentication
│   ├── OAuth2 / JWT
│   └── Method security
├── Spring Cloud
│   ├── Config Server
│   ├── Service Discovery (Eureka)
│   ├── Gateway
│   ├── Circuit Breaker (Resilience4j)
│   └── OpenFeign
├── Spring Batch
├── Spring Integration
├── Spring Kafka / AMQP
└── Spring Native (GraalVM)

디렉터리 구조 (관례)

src/
├── main/
│   ├── java/com/example/myapp/
│   │   ├── MyApplication.java
│   │   ├── controller/
│   │   ├── service/
│   │   ├── repository/
│   │   ├── domain/
│   │   ├── dto/
│   │   ├── config/
│   │   └── exception/
│   └── resources/
│       ├── application.yml
│       ├── static/
│       ├── templates/
│       └── db/migration/
└── test/
    └── java/com/example/myapp/

도메인 단위 패키지(user/, order/)가 더 좋은 패턴이라는 의견(DDD).

Spring과 Java vs Kotlin

Kotlin은 Spring의 1급 시민. data class, null safety, extension function이 Spring과 잘 어울림.

@Entity
data class User(
    @Id @GeneratedValue val id: Long? = null,
    val email: String,
    val name: String,
)

@Service
class UserService(private val userRepository: UserRepository) {
    fun findByEmail(email: String): User =
        userRepository.findByEmail(email) ?: throw NotFoundException()
}

3.0+에선 Kotlin 비즈니스 로직 + Java 인프라가 흔함.

학습 경로

  1. Spring Boot 빠른 시작 + REST API
  2. Spring Data JPA (DB 접근)
  3. Spring Security (인증)
  4. Spring Test (단위 + 통합)
  5. AOP, custom configuration
  6. WebFlux (reactive)
  7. Spring Cloud (마이크로서비스)
  8. Actuator, 모니터링

다른 Java 프레임워크와 비교

Spring BootQuarkusMicronautHelidon
시작 시간보통빠름 (Native)빠름빠름
메모리많음적음적음적음
GraalVM부분우선우선우선
생태계매우 큼작음
학습 자료매우 많음많음적음

서버리스/CLI/마이크로 → Quarkus/Micronaut. 일반 엔터프라이즈 → Spring Boot.

이 개념을 다룬 위키 페이지 (2)

💬 댓글

사이트 검색 / 명령어

검색

스크롤 = 확대/축소 · 드래그 = 이동 · 0 = 원래 크기 · ESC = 닫기