spring boot reactive νλ‘μ νΈλ₯Ό μν ν νλ¦Ώ μ λλ€. JPAμ λν μ€μ λ ν¬ν¨λμ΄ μμ΅λλ€.
- μ£Όμ λ΄μ©μ λν μ€λͺ
- νλ‘μ νΈ νμ€ κ΅¬μ± μ¬μ© μ μμλμ΄μΌ ν μ¬ν
- profile ꡬλΆ
- API λ¬Έμ μμ±
- ν μ€νΈ μ½λ μμ±μ λνμ¬
- docker λ°°ν¬ κ΄λ ¨ μ¬ν
μμ±κΈ°μ€μΌ : 2023λ 4μ 17μΌ
- java 17
- Spring boot 3.0.5
- gradle 7.5.1 (release 2022.08.05)
- QueryDSL 5.0.0
- flyway 9.8.2
- PostgreSQL 14.6
- PostgreSQL Driver 42.5.1
- PostgreSQL R2DBC Driver 1.0.0.RELEASE
- Mongo DB 6.0.3
- Spring Kafka
- restdocs 3.0.0 (with restdocs-api-spec)
- junit jupiter 5.9.1, assertj 3.23.1
- testcontainers 1.18.0
- Java 17 λ² μ΄μ€λΌμΈ
- μ€νμ μΈ Spring Native νλ‘μ νΈλ₯Ό λ체νλ GraalVMμΌλ‘ λ€μ΄ν°λΈ μ΄λ―Έμ§ μμ± μ§μ
- Micrometer λ° Micrometer Tracing μΌλ‘ κ΄μ°° κ°λ₯μ± ν₯μ
- EE 9 κΈ°μ€μΌλ‘ Jakarta EE 10 μ§μ
μΈλΆλ΄μ©μ https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Release-Notes μ μ°Έμ‘°νμμμ€.
spring boot 3.0.0 곡μ λ¬Έμλ₯Ό λ²μν λ΄μ©μ μ 리ν΄λμμΌλ μ°Έκ³ νμμμ€.
- Spring Boot 3.0 Release Notes
- Spring Framework 6.x λ³κ²½μ¬ν
- Spring Boot 3.0 λ§μ΄κ·Έλ μ΄μ κ°μ΄λ
Spring Boot 3.0.0 μ΄ λ¦΄λ¦¬μ¦ λλ©΄μ Java 17μ λ² μ΄μ€λ‘ μ§μνκ² λμμ΅λλ€ (https://spring.io/blog/2022/11/24/spring-boot-3-0-goes-ga).
Java 17μ Spring Boot 3 μμμ κΈ°μ€ μΈμ΄μ΄λ©° Spring Boot 3.0 μμλ Java 19 λ₯Ό μ§μν©λλ€. Java 17μ Java 11 λλΉ LTS μ§μ κΈ°κ°μ΄ 2026λ 9μκΉμ§ λ κΈ΄ μ§μμ 보μ₯ν©λλ€.
Spring Data JPA + JDBCλ₯Ό μ¬μ©νμ¬ ORM ννμ repository ꡬν λ°©μμ μ¬μ©ν©λλ€.
μΌλ°μ μΌλ‘ μ¬μ©λλ RDBMSλ PostgreSQL μ λλ€.
Spring Reactive Stack μ R2DBC λ₯Ό μ΄μ©ν repository ꡬνλ°©μμ μ¬μ©ν©λλ€.
μΌλ°μ μΌλ‘ μ¬μ©λλ RDBMSλ PostgreSQL μ λλ€.
Spring Reactive Stack μ MongoDB λ₯Ό μ΄μ©ν repository ꡬνλ°©μμ μ¬μ©ν©λλ€.
μλμ ν μ€ν νλ μμν¬λ₯Ό κΈ°λ³Έμ μΌλ‘ μ¬μ©ν©λλ€.
- junit5 (with mockito)
- org.assertj
- com.squareup.okhttp3:mockwebserver
μ΄ spring boot νλ‘μ νΈ νμ€μμλ μ¬μ©νκ³ μ νλ λͺ¨λ κΈ°μ μ€νμ λν νλ μμν¬ μμ‘΄μ±κ³Ό μ€μ , μμ μ½λ λ±μ΄ μμ±λμ΄ μμ΅λλ€. κ·Έλ¦¬κ³ μ μ©λ κΈ°μ μ€νμ λνμ¬ ν¨κ» μ¬μ© κ°λ₯ν κ²μ μ μ λ‘ κ΅¬μ±λμ΄ μμ΅λλ€. μλ₯Ό λ€μ΄ JPA-Datasourceμ MongoDB-Reactive λ₯Ό μ¬μ©νμ¬ λͺ¨λ μ¬μ©νλ κ²μ μλ―Έν©λλ€.
μλ‘μ΄ νλ‘μ νΈλ‘ κ°λ°μ μμνκ³ μ ν λ νλ‘μ νΈ κ΅¬μ±μ μ΄ν΄νκ³ μ¬μ©νκ³ μ νλ λΆλΆμ μ μΈν λ€λ₯Έ μμ‘΄μ±κ³Ό μ€μ , μ½λλ₯Ό μ κ±°νκ³ μ¬μ©νμμμ€.
4κ°μ§ profile λ‘ κ΅¬λΆνκ³ κ°κ°μ μ©λλ₯Ό ꡬλΆν©λλ€. Spring boot 컨ν μ΄λλ₯Ό μ€ννκ±°λ λ¨μ ν μ€νΈλ₯Ό μ€νν λ profile μ΄ μ§μ λμ§ μμ κ²½μ°λ λͺ¨λ profile μνμμ μν κ²°κ³Όκ° λμΌν¨μ μλ―Έν©λλ€.
κ°μ₯ μ¬νν ν μ€νΈλ₯Ό μν profile μ λλ€. μλμ ν μ€νΈ μΌμ΄μ€μ λν μ΄ profile μ μ¬μ©ν©λλ€.
λ¨μ ν μ€νΈλ₯Ό μν profile μ λλ€. μ½κ³ κ°κ²°ν λ¨μ ν μ€νΈλ₯Ό μνμ¬ μλμ κ°μ μ μ½ μ¬νμ μ μ λ‘ ν©λλ€.
- μΈλΆ μλΉμ€μ λν μμ‘΄μ±μ΄ μλ ν΄λμ€ ν¨μμ λ¨μ ν μ€νΈ
- mocking μ μ΄μ©ν ν μ€νΈ
- κ·Έ μΈ ν μ€νΈλ₯Ό μνν¨μ μμ΄ μ€νλλ μ½λ μΈμ νμν κ²μ΄ μλ κ²½μ°
μΈλΆ μλΉμ€ λλ νλ μμν¬μ λν μμ‘΄μ±μ΄ μλ κ²½μ°μλ testcontainers λ₯Ό νμ©ν ν μ€νΈλ₯Ό μμ± ν©λλ€. μ΄ κ²½μ° tc profile μ μ¬μ©νλ©° νμν μ€μ λ€μ μΆκ°νμ¬ κ΄λ¦¬ν©λλ€.
local
profile μ μ΄μ©ν ν
μ€νΈλ μμ‘΄λλ μΈλΆ μλΉμ€ λλ νλ μμν¬λ₯Ό μ€λΉνμ¬ μ¬μ©νλ κ²μ λΉμ·ν©λλ€. νμ§λ§ tc profile μμλ ν
μ€νΈ suite λ¨μλ‘ μμ‘΄ μλΉμ€κ° μ€λΉλκ³ ν
μ€νΈκ° μ’
λ£λλ©΄ μμ λ©λλ€. μμ‘΄ μλΉμ€κ° νλ°μ±μ κ°μ§λ κ²μ μλ―Έν©λλ€.
κ°λ°κ³Όμ μμ ν μ€νΈ λλ λλ²κΉ μ μν profile μ λλ€. μ°κ³λλ ν μλΉμ€λ€μ λ‘컬νκ²½μ ꡬμΆνμ¬ μ€μ ν©λλ€. λͺ¨λ μλΉμ€κ° λ‘컬μ ꡬμ±λμ§λ§ μ€μ μ λμΌν μλΉμ€μ λλ€.
κ°λ°μλ² νκ²½μ μλ―Έν©λλ€. Spring boot λ κ°λ°νκ²½μμ μ€ννμ§λ§ DB μλ², λ©μμ§ μλ² λ± μ°κ³ μμ€ν μ κ°λ°μλ² νκ²½μ μ°κ²°ν©λλ€.
μΌλ°μ μΌλ‘ ν΅ν©ν μ€νΈλ₯Ό μν μ€μ μ λλ€.
μ΄μνκ²½μ μλ―Έν©λλ€. μ΄μνκ²½μ νμν μ€μ λ§μ μ μνκ³ debug μ μν μ€μ μ μ κ±°ν©λλ€.
μ΄ profile μ κ°λ°λ¨κ³μμλ μ¬μ©λμ§ μμΌλ©° μ΄μνκ²½μ λ°°ν¬λ₯Ό μνμ¬ μ¬μ©λλ profile μ λλ€.
test profile μ μ΄μ©νμ¬ in-memory DBμ λν ν μ€νΈλ₯Ό ν©λλ€. νμ§λ§ in-memory DB μ h2, embeded DB μ κ²½μ°μλ νΉμ λ²€λμ DBMSμ λν ν μ€νΈ μ λ’°μ±μ 보μ₯νμ§ λͺ»ν©λλ€.
tc profile μ testcontainers λ₯Ό μ¬μ©μ νμν μ¬νμ μ€μ νκ³ μ΄λ₯Ό μ¬μ©νμ¬ ν μ€νΈ μΌμ΄μ€ μνμ μ¬μ©ν μ μμ΅λλ€.
IDEλ intellij IDEAμ μ¬μ©μ μ μ λ‘ μ€λͺ ν©λλ€. Intellij IDEAλ 2022.3 λ₯Ό κΈ°μ€μΌλ‘ μμ±λμμ΅λλ€.
μλμ μ€μ μ κ°λ°μμ μ€μ μ κΈ°νΈμ λ°λΌ λ³κ²½ν μ μμ΅λλ€. λ³κ²½νκ² λλ©΄ ν μ€νΈ νκ²½, QueryDSL μ€μ κ³Ό κ΄λ ¨λ λΆλΆμ΄ μν₯μ λ°μ μ μμ΅λλ€.
Settings > Build, Execution, Deployment > Build Tools > Gradle μ μλ νλͺ©μ μ€μ ν©λλ€.
- Build and run using : IntelliJ IDEA
- Run tests using : IntelliJ IDEA
- Gradle JVM : Project SDK
Spring Boot μ μ€ν μνμμ μ½λ μμ μ λν μλ λΉλ ν reload λ₯Ό μ€μ νλ λ°©λ²μ λν λ΄μ©μ λλ€.
- settings > Build, Execution, Deployment > Compiler μ βBuild project automaticallyβ λ₯Ό νμ±νν©λλ€.
- Spring Boot μ Run Configuration μ μλ νλͺ©μ μ€μ ν©λλ€.
- Modify Options > On βUpdateβ action : Update classes and resources
- Modify Options > On frame deactivation : Update classes and resources
Intellijμ Settings > Build, Execution, Deployment > Compiler > Annotation Processors μμ μλμ κ°μ΄ μ€μ ν©λλ€. lombok, querydsl λ± μ΄λ Έν μ΄μ κ³Ό κ΄λ ¨λ κ°λ°νκ²½μ λν λΉλ ν΄λμ€κ° μμ±λ©λλ€.
μ€μ κ°μ μλ μ΄λ―Έμ§μ λ€λ₯΄κ² ν μ μμ΅λλ€. μ΄ κ²½μ° λ³κ²½λ μ¬νμ λ§μΆμ΄ gradleκ³Ό IDE μ€μ μ λ³κ²½ν΄μΌ ν μ μμ΅λλ€.
Intellij μμ Spring Boot, JUnit ν μ€νΈ λ± run μ μ€νν κ²½μ° μ€λ₯κ° λ°μνλ κ²½μ° Shorten command line μΌλ‘ μ€ννμμμ€.
MacOS μμλ μ€λ₯κ° λ°μνλ κ²½μ°κ° μμμΌλ©° Windows 11 μμ λ°μνμμ΅λλ€.
νλ‘μ νΈ API λ¬Έμ μμ±μ μλ μ£Όμ μ¬νμ μ€μν©λλ€.
- Open API 3 SpecμΌλ‘ μμ±ν©λλ€.
- Open API 3 Specμ νμΌ ν¬λ§·μ YAMLλ‘ μμ±ν©λλ€.
- Spring REST Docs λ‘ ν μ€νΈ κΈ°λ°μ API λ¬Έμ μμ±νλ©°, μμ±λ λ¬Έμμμ OAS 3 Specμ μμ±ν©λλ€.
- epages-restdocs-api-spec μ μ μ©νμ¬ μμ±λ restdocs λ₯Ό κΈ°λ°μΌλ‘ OAS 3 Specμ μμ±ν©λλ€.
νλ‘μ νΈ κ°λ° μ¬κ±΄μ λ°λΌ λ¬Έμλ₯Ό μμ±νλ λ°©μμ μ νν μ μμ΅λλ€. κ°μ₯ κΆμ₯λλ λ°©λ²μ Spring REST Docsλ₯Ό μ¬μ©νλ κ²μ λλ€.
Spring REST Docs λ‘ μμ±ν μ μλ€λ©΄ μλ λ°©λ²μ μ ννμμμ€.
- OAS3 Specμ java μ΄λ Έν μ΄μ μ μ΄μ©ν μμ± λ°©λ² (swagger v3 oas)
- OAS3 Spec κ·κ²©μ YAML λ¬Έμλ₯Ό μμ± (μ΄λ Έν μ΄μ μ μ¬μ©νμ§ μλ λ°©λ²)
src/docs/oas-doc.yaml
μ λ¬Έμ λ΄μ©μ μμ±ν©λλ€. μμ±λ specμ κ²μ¦μ΄ λμλ€λ κ²μ μ μ λ‘ μ΄λ₯Ό λ°°ν¬ν©λλ€.
λ§μ½ Spring REST Docs λ₯Ό μ¬μ©νλ€λ©΄ μ spec νμΌμ λ΄μ©μ μμ±νμ§ μμΌλ©°, Spring REST Docsλ₯Ό μ΄μ©νμ¬ OAS 3 Spec μ μμ±ν΄μΌ ν©λλ€.
μλ μ€ν μμ€ νλ‘μ νΈλ₯Ό μ΄μ©νμ¬ λ³νν μ μμ΅λλ€.
https://github.com/ePages-de/restdocs-api-spec
μμ§ Spring Boot 3.x μμ μ¬μ©ν μ μμΌλ©°, μΆν μ λ°μ΄νΈμ λ°λΌ μ μ©λ μμ μ λλ€.
- Controller, Service, Repository, Component λ± κ°κ°μ μμλ€μ κ°μμ ν μ€νΈλ§ μννκ³ μ£Όμ λλ μμ‘΄ ν΄λμ€μ λν κ²μ mock κ°μ²΄λ₯Ό μ¬μ©νμ¬ μμ±ν©λλ€.
- Controller ν μ€νΈλ ν΄λΌμ΄μΈνΈλ‘λΆν° μ λ¬λλ request μ μ²λ¦¬μ response μ λν κ²μ¦ ν μ€νΈλ₯Ό μμ±ν©λλ€.
- Service, component ν μ€νΈλ μ²λ¦¬ νλ‘μΈμ€ λ‘μ§μ λν ν μ€νΈλ₯Ό μμ±ν©λλ€.
- Repository ν μ€νΈλ DBμ λν CRUD κ° μ¬λ°λ₯΄κ² μ²λ¦¬ λλκ°μ λν ν μ€νΈλ₯Ό μμ±ν©λλ€.
ν μ€νΈμ λ©±λ±μ±κ³Ό μ€μ μ¬μ© DBMS μ λν ν μ€νΈ μ λ’°μ±μ μνμ¬ Testcontainers (https://www.testcontainers.org/) λ₯Ό μ μ©νμμ΅λλ€. Testcontainers λ₯Ό μ΄μ©ν ν μ€νΈ μΌμ΄μ€μμλ λ°μ΄ν°μ λ‘€λ°±μ΄λ μ¬μ μ€λΉμμ λ±μ λν μ²λ¦¬λ₯Ό νμ§ μμλ λ©λλ€.
Testcontainers λ₯Ό μ΄μ©ν ν μ€νΈ μΌμ΄μ€ μμ±μ κ°μ νμ§ μμ΅λλ€. νμ§λ§ λ°λ³΅νμ¬ ν μ€νΈ μ€νμ ν μ μλλ‘ κ΅¬νν΄μΌ ν©λλ€. ν μ€νΈλ₯Ό μν λ³λμ μλΉμ€κ° μ€λΉλμ΄μΌ νλ€λ©΄ install κ°μ΄λμ μ€λΉκ³Όμ μ λν λ¬Έμλ₯Ό μ 곡ν΄μΌ ν©λλ€.
- DataSource PostgreSQL JPA Repository ν μ€νΈ μμ± κ°μ΄λ
- DataSource PostreSQL QueryDSL Repository ν μ€νΈ μμ± κ°μ΄λ
- R2DBC PostgreSQL Repository ν μ€νΈ μμ± κ°μ΄λ
- Reactive MongoDB Repository ν μ€νΈ μμ± κ°μ΄λ
- Selenium ν μ€νΈ μμ± κ°μ΄λ
- Kafka Producer/Consumer ν μ€νΈ μμ± κ°μ΄λ
νλ‘μ νΈμ docker λλ ν 리 νμμ νλ‘μ νΈμ ν μ€νΈμ μ€νμ μν dockerfile, docker-compose νμΌ μμ κ° μμ±λμ΄ μμ΅λλ€. κ° μν©μ λ§κ² λ³κ²½νμ¬ μ¬μ©νμκΈ° λ°λλλ€. μ£Όμ λ΄μ©μ μλμ κ°μ΅λλ€.
- jenkins : jenkins 곡μ docker μ΄λ―Έμ§μ openjdk-17, docker μ€μΉκ° μ μ©λ dockerfile
- local_mariadb : λ‘컬 ν μ€νΈ νκ²½μ μν mariadb docker-compose
- local_mongodb : λ‘컬 ν μ€νΈ νκ²½μ μν mongodb docker-compose
- local_postgres : λ‘컬 ν μ€νΈ νκ²½μ μν postgres docker-compose
- spring-boot : νλ‘μ νΈμ spring boot λ°°ν¬μ© dockerfileκ³Ό docker-compose μμ±, νλ‘μ νΈ λΉλ ν docker μ΄λ―Έμ§ μμ± shellscript, jenkins pipeline μμ
- swagger : μμ±λ OAS λ΄μ©μ swagger μλ²λ‘ μ€ννκΈ° μν docker-compose