| name | springboot-patterns |
| description | Use when building Spring Boot services, configuring profiles, implementing caching/async, setting up Actuator/Micrometer, or creating REST clients. Do NOT use for JPA (use jpa-patterns), API design (use api-design), security (use springboot-security), testing (use springboot-tdd). |
| paths | **/*.java, **/build.gradle*, **/pom.xml, **/application*.yml, **/application*.properties |
Spring Boot Core Patterns
๋ฒ์ ๊ฒฝ๊ณ์ ํ๋ก๋์
๊ธฐ๋ณธ๊ฐ๋ง ๋ด๋๋ค. Spring Boot ์ผ๋ฐ ์ง์์ ๋ชจ๋ธ์ ์ด๋ฏธ ์์.
๋ฒ์ ์ปจํ
์คํธ: Spring Boot 4 (ํ์ฌ GA โ Spring Framework 7 ๊ธฐ๋ฐ, Java 17+ / Jakarta EE 11). Boot 3.x๋ legacy์ด๋ prod์์ ์ฌ์ ํ ํํจ (3.5 = ๋ง์ง๋ง 3.x, Framework 6.2 ๊ธฐ๋ฐ). ์ฝ๋ ์์ฑ ์ ํ๋ก์ ํธ์ Boot ๋ฒ์ ์ ๋จผ์ ํ์ธํ๋ผ.
CRITICAL Rules
- ALWAYS constructor injection โ field injection ๊ธ์ง (ํ
์คํธ ๋ถ๊ฐ, ์์กด์ฑ ์จ๊น)
- ALWAYS
spring.mvc.problemdetails.enabled=true โ RFC 9457 ํ์ค ์๋ฌ ์๋ต (ProblemDetail)
- NEVER return entity directly from controller โ DTO ๋ถ๋ฆฌ ํ์
- ALWAYS externalize secrets โ
${ENV_VAR} ๋๋ Vault, ์ ๋ ํ๋์ฝ๋ฉ ๊ธ์ง
- PREFER record for DTOs and @ConfigurationProperties
- ALWAYS graceful shutdown โ
server.shutdown=graceful
- NEVER catch generic Exception silently โ ๋ก๊ทธ + ์ ์ ํ HTTP ์ํ ๋ฐํ
- ALWAYS
spring.main.keep-alive=true when virtual threads enabled โ daemon thread๋ก JVM ์กฐ๊ธฐ ์ข
๋ฃ ๋ฐฉ์ง
Production Defaults
spring:
mvc:
problemdetails:
enabled: true
jackson:
default-property-inclusion: non_null
deserialization:
fail-on-unknown-properties: false
lifecycle:
timeout-per-shutdown-phase: 30s
server:
shutdown: graceful
Gotchas
- โ
@Autowired ํ๋ ์ฃผ์
์ฌ์ฉ โ ์์ฑ์ ์ฃผ์
ํ์
- โ application.yml์ ๋ฏผ๊ฐ ์ ๋ณด ํ๋์ฝ๋ฉ โ ํ๊ฒฝ๋ณ์ ๋๋ Vault
- โ
@Configuration ํด๋์ค์ ๋น์ฆ๋์ค ๋ก์ง โ ์ค์ ๋ง ๋ด์ ๊ฒ
- โ virtual threads ์ผ๊ณ
spring.main.keep-alive ๋๋ฝ โ ์ด๋ฒคํธ ์๋ ์ฑ์ด ์กฐ์ฉํ ์ข
๋ฃ๋จ
- โ HTTP ํด๋ผ์ด์ธํธ๋ก RestTemplate ์ ๊ท ์์ฑ โ
RestClient ๋๋ HTTP Interface (Boot 3.2+)
- โ ๊ตฌ์กฐํ(JSON) ๋ก๊น
์
logstash-logback-encoder ์์กด์ฑ ์ถ๊ฐ โ Boot 3.4+๋ ๋ด์ฅ: logging.structured.format.console=ecs|logstash|gelf ํ ์ค์ด๋ฉด ๋จ
Cross-References
| Topic | Skill |
|---|
| JPA/Hibernate, Spring Data | jpa-patterns |
| REST API design principles | api-design |
| Virtual Threads, Records, Sealed Types | java-modern-patterns |
| Spring Security | springboot-security |
| TDD, MockMvc, JUnit 5 | springboot-tdd |
| PR/deploy verification | springboot-verification |
| SQL query optimization | sql-optimization-patterns |