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

5.0 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-spring-framework Spring Framework 10_Wiki/Topics verified self
Spring
Spring Boot
Spring Core
none A 0.9 applied
java
framework
dependency-injection
spring-boot
2026-05-10 pending
language framework
java 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

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

Constructor injection 의 service

@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)

@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

public interface OrderRepository extends JpaRepository<Order, Long> {
    List<Order> findByCustomerIdAndCreatedAfter(Long customerId, Instant after);
}

Configuration properties

@ConfigurationProperties("payments")
public record PaymentsConfig(String url, Duration timeout, String apiKey) {}
# application.yml
payments:
  url: https://api.stripe.com
  timeout: 5s
  api-key: ${STRIPE_KEY}

Virtual threads (Boot 3.2+, Java 21)

spring:
  threads:
    virtual:
      enabled: true

WebFlux reactive endpoint

@GetMapping("/stream")
public Flux<Event> stream() {
    return eventRepo.findAll().delayElements(Duration.ofMillis(100));
}

Test (slice)

@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

🤖 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