Files
2nd/10_Wiki/Topics/Architecture/Spring Framework.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

182 lines
5.0 KiB
Markdown

---
id: wiki-2026-0508-spring-framework
title: Spring Framework
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Spring, Spring Boot, Spring Core]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [java, framework, dependency-injection, spring-boot]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: java
framework: spring-boot
---
# Spring Framework
## 매 한 줄
> **"매 Java enterprise 의 IoC container — 매 Beans, AOP, MVC, Boot 의 ecosystem"**. Rod Johnson (2003) 의 J2EE 대체. 2026 현재 Spring Boot 3.4 (Java 21+, virtual threads, AOT/GraalVM native) 가 매 backend Java 의 de-facto.
## 매 핵심
### 매 IoC / DI
- **ApplicationContext**: 매 Bean 의 lifecycle 관리.
- **`@Component`, `@Service`, `@Repository`, `@Controller`**: 매 stereotype.
- **Constructor injection**: 매 권장 (final field, immutability).
### 매 modules
- **Spring Core**: IoC, DI, Resource, SpEL.
- **Spring MVC / WebFlux**: HTTP (Servlet vs reactive).
- **Spring Data**: JPA, MongoDB, Redis repository abstraction.
- **Spring Security**: Auth (OAuth2, JWT, OIDC).
- **Spring Boot**: 매 auto-configuration, embedded Tomcat/Netty.
### 매 응용
1. REST API backend (Boot + Web + Data JPA).
2. Reactive microservice (WebFlux + R2DBC).
3. Batch job (Spring Batch).
## 💻 패턴
### Spring Boot 3.4 application
```java
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
```
### Constructor injection 의 service
```java
@Service
public class OrderService {
private final OrderRepository repo;
private final PaymentClient payments;
public OrderService(OrderRepository repo, PaymentClient payments) {
this.repo = repo;
this.payments = payments;
}
public Order place(NewOrder cmd) {
var charge = payments.charge(cmd.amount());
return repo.save(new Order(cmd, charge.id()));
}
}
```
### REST controller (Java 21 records)
```java
@RestController
@RequestMapping("/orders")
public class OrderController {
private final OrderService service;
public OrderController(OrderService s) { this.service = s; }
@PostMapping
public ResponseEntity<Order> create(@Valid @RequestBody NewOrder cmd) {
return ResponseEntity.status(201).body(service.place(cmd));
}
}
public record NewOrder(@NotBlank String sku, @Positive long amount) {}
```
### Spring Data JPA repository
```java
public interface OrderRepository extends JpaRepository<Order, Long> {
List<Order> findByCustomerIdAndCreatedAfter(Long customerId, Instant after);
}
```
### Configuration properties
```java
@ConfigurationProperties("payments")
public record PaymentsConfig(String url, Duration timeout, String apiKey) {}
```
```yaml
# application.yml
payments:
url: https://api.stripe.com
timeout: 5s
api-key: ${STRIPE_KEY}
```
### Virtual threads (Boot 3.2+, Java 21)
```yaml
spring:
threads:
virtual:
enabled: true
```
### WebFlux reactive endpoint
```java
@GetMapping("/stream")
public Flux<Event> stream() {
return eventRepo.findAll().delayElements(Duration.ofMillis(100));
}
```
### Test (slice)
```java
@WebMvcTest(OrderController.class)
class OrderControllerTest {
@Autowired MockMvc mvc;
@MockBean OrderService service;
@Test
void createsOrder() throws Exception {
when(service.place(any())).thenReturn(new Order(1L, "sku", 100));
mvc.perform(post("/orders").contentType(APPLICATION_JSON)
.content("""{"sku":"sku","amount":100}"""))
.andExpect(status().isCreated());
}
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Java enterprise backend | Spring Boot |
| 매 reactive, high-concurrency I/O | WebFlux + R2DBC |
| 매 traditional blocking I/O + Java 21 | Spring MVC + virtual threads |
| Native binary (cold start, low memory) | Spring Boot AOT + GraalVM |
| Lightweight Java (no DI ecosystem) | Quarkus / Micronaut / pure Javalin |
**기본값**: Spring Boot 3.4 + Java 21 + virtual threads + Spring MVC.
## 🔗 Graph
- 부모: [[Inversion of Control]]
- 변형: [[Spring Boot]]
- 응용: [[Microservices]]
## 🤖 LLM 활용
**언제**: Java backend, 매 enterprise integration (JPA, security, messaging) 필요.
**언제 X**: 매 ultra-low memory (serverless cold start) — Quarkus native 의 superior; 매 non-Java stack.
## ❌ 안티패턴
- **Field injection (`@Autowired` private field)**: 매 testability X, 매 final X. Constructor 의 사용.
- **God `@Configuration`**: 매 100+ bean 의 한 file — 매 module 별 분리.
- **`@Transactional` on private**: 매 proxy 의 work X. Public + self-injection 패턴.
- **Boot 1.x / Java 8**: 매 EOL, 매 vulnerable, 매 upgrade.
## 🧪 검증 / 중복
- Verified (spring.io docs, Spring Boot 3.4 release notes 2025).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — Spring Boot 3.4 / Java 21 modern patterns |