Files
2nd/10_Wiki/Topic_Programming/Architecture/Spring Framework.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +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 |