[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,97 +2,181 @@
|
||||
id: wiki-2026-0508-spring-framework
|
||||
title: Spring Framework
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-C45BD6]
|
||||
aliases: [Spring, Spring Boot, Spring Core]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [java, framework, dependency-injection, spring-boot]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - Spring Framework"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: java
|
||||
framework: spring-boot
|
||||
---
|
||||
|
||||
# [[Spring Framework|Spring Framework]]
|
||||
# Spring Framework
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> Spring Framework는 자바(Java) 환경에서 사용되는 프레임워크로, 주로 내장된 DI(의존성 주입) 컨테이너를 통해 컴포넌트 간의 결합도를 낮추는 역할을 합니다 [1]. 또한 런타임 시점에 적용되는 Spring AOP를 지원하여 트랜잭션 관리 및 캐시 처리와 같은 횡단 관심사의 모듈화를 돕습니다 [2, 3]. 다만 제공된 문헌에는 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.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **의존성 주입(DI)과 결합도 감소**
|
||||
Spring Framework는 내장된 의존성 주입(Dependency Injection) 컨테이너를 제공하여 SOLID 원칙 중 하나인 의존성 역전 원칙(Dependency [[Inversion|Inversion]] Principle, DIP)을 훨씬 쉽게 구현할 수 있도록 지원합니다 [1]. 이를 통해 소프트웨어 컴포넌트들을 효과적으로 분리(decoupling)하고 유연한 설계를 가능하게 합니다 [1].
|
||||
## 매 핵심
|
||||
|
||||
* **Spring AOP (관점 지향 프로그래밍) 지원**
|
||||
* **런타임 위빙(Runtime Weaving):** Spring AOP는 애플리케이션의 실제 코드와 Aspect를 결합하는 위빙 과정에 있어 프로그램 실행 시점에 적용되는 런타임 위빙 방식을 사용합니다 [2].
|
||||
* **조인 포인트(Join Point)의 한계:** 프로그램 실행 중 Aspect를 적용할 수 있는 지점인 조인 포인트에 대해, Spring AOP는 오직 '메서드 실행 시점'만을 지원합니다 [4]. 따라서 이보다 더 세부적인 제어가 필요한 상황에서는 AspectJ를 대신 사용해야 합니다 [5].
|
||||
* **주요 활용 사례:** 데이터베이스 트랜잭션을 관리하는 `@Transactional` 어노테이션과 성능 개선을 위해 자주 호출되는 메서드 결과를 캐싱하는 Spring Cache 라이브러리는 모두 이러한 AOP 기능을 활용하여 구현되어 있습니다 [3].
|
||||
### 매 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.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Graphics & Performance 분야의 자동 자산화 수행.
|
||||
### 매 응용
|
||||
1. REST API backend (Boot + Web + Data JPA).
|
||||
2. Reactive microservice (WebFlux + R2DBC).
|
||||
3. Batch job (Spring Batch).
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** Dependency Injection (DI), Aspect-Oriented Programming (AOP)
|
||||
- **Projects/Contexts:** SOLID [[Principles|Principles]], [[객체 지향 프로그래밍 (OOP)|객체 지향 프로그래밍 (OOP]]
|
||||
- **Contradictions/Notes:** 소스에 따르면 Spring AOP는 런타임에 적용되어 유용한 모듈화를 제공하지만, 오직 메서드 실행 시점의 조인 포인트만 지원하는 한계가 있어 더 정밀한 제어를 원할 경우 AspectJ 사용이 권장됩니다 [4, 5].
|
||||
## 💻 패턴
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-18*
|
||||
|
||||
---
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
### Spring Boot 3.4 application
|
||||
```java
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class, args);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Constructor injection 의 service
|
||||
```java
|
||||
@Service
|
||||
public class OrderService {
|
||||
private final OrderRepository repo;
|
||||
private final PaymentClient payments;
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
public OrderService(OrderRepository repo, PaymentClient payments) {
|
||||
this.repo = repo;
|
||||
this.payments = payments;
|
||||
}
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
public Order place(NewOrder cmd) {
|
||||
var charge = payments.charge(cmd.amount());
|
||||
return repo.save(new Order(cmd, charge.id()));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### REST controller (Java 21 records)
|
||||
```java
|
||||
@RestController
|
||||
@RequestMapping("/orders")
|
||||
public class OrderController {
|
||||
private final OrderService service;
|
||||
public OrderController(OrderService s) { this.service = s; }
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
@PostMapping
|
||||
public ResponseEntity<Order> create(@Valid @RequestBody NewOrder cmd) {
|
||||
return ResponseEntity.status(201).body(service.place(cmd));
|
||||
}
|
||||
}
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
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
|
||||
- 부모: [[Java]] · [[Inversion of Control]]
|
||||
- 변형: [[Spring Boot]] · [[Spring WebFlux]] · [[Spring Security]]
|
||||
- 응용: [[Microservices]] · [[REST API]]
|
||||
- Adjacent: [[Quarkus]] · [[Micronaut]] · [[Hibernate]]
|
||||
|
||||
## 🤖 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 |
|
||||
|
||||
Reference in New Issue
Block a user