ποΈ[SpringBoot] μ€νλ§ λΆνΈλ 무μμΌκΉμ?
π κ°μ
SpringBootλ Spring Frameworkλ₯Ό κΈ°λ°μΌλ‘ ν Java λ°±μλ μ ν리μΌμ΄μ κ°λ° νλ μμν¬μ λλ€. 볡μ‘ν μ€μ κ³Όμ μ μλννκ³ , λ΄μ₯ μλ²λ₯Ό μ 곡νμ¬ κ°λ°μκ° λΉμ¦λμ€ λ‘μ§μ λ μ§μ€ν μ μλλ‘ λμμ€λλ€.
π€ μ νλ μμν¬κ° νμνκ°?
κ·λͺ¨κ° ν¬κ³ 볡μ‘ν μ ν리μΌμ΄μ μ κ°λ°ν λ, κ°λ°μκ° μ²μλΆν° λκΉμ§ λͺ¨λ λΆλΆμ κ°λ°νλ κ²μ λΉν¨μ¨μ μ λλ€. νλ μμν¬λ λ€μκ³Ό κ°μ μ΄μ μ μ 곡ν©λλ€:
- κ°λ° μκ° λ¨μΆ: κ²μ¦λ ꡬ쑰μ κΈ°λ₯ μ 곡
- μ μ§λ³΄μ νΈμμ±: νμ€νλ ν¨ν΄κ³Ό ꡬ쑰
- μ¬μ¬μ© κ°λ₯ν μ»΄ν¬λνΈ: λΌμ΄λΈλ¬λ¦¬λ³΄λ€ ν¬κ΄μ μΈ κ°λ° νκ²½
π Spring Ecosystem
Spring Framework
λͺ¨λ Spring νλ‘μ νΈμ ν΅μ¬ κΈ°λ°μ΄ λλ νλ μμν¬
μ£Όμ κΈ°λ₯:
- μμ‘΄μ± μ£Όμ (Dependency Injection)
- μ μ΄μ μμ (Inversion of Control)
- Spring MVC λͺ¨λΈ
- λ°μ΄ν°λ² μ΄μ€ μ κ·Ό, λ©μμ§, νΈλμμ μ§μ
Spring Boot
Spring Frameworkλ₯Ό λ μ½κ³ λΉ λ₯΄κ² μ¬μ©ν μ μλλ‘ νλ λꡬ
ν΅μ¬ νΉμ§:
- μλ κ΅¬μ± (Auto Configuration)
- λ΄μ₯ μΉ μ ν리μΌμ΄μ μλ² (Tomcat, Jetty λ±)
- λ¨λ μ€ν κ°λ₯ν JAR νμΌ μμ±
- 볡μ‘ν μ€μ κ³Όμ κ°μν
κΈ°ν Spring νλ‘μ νΈ
- Spring Data: λ°μ΄ν° μ‘μΈμ€ μΆμν
- Spring Security: 보μ κΈ°λ₯
- Spring Cloud: λ§μ΄ν¬λ‘μλΉμ€ μν€ν μ² μ§μ
β¨ Spring Frameworkμ ν΅μ¬ νΉμ§
1. μ μ΄μ μμ (IoC, Inversion of Control)
κ°μ²΄μ μμ±κ³Ό κ΄λ¦¬λ₯Ό κ°λ°μκ° μλ Spring Containerκ° λ΄λΉ
2. μμ‘΄μ± μ£Όμ (DI, Dependency Injection)
κ°μ²΄ κ°μ μμ‘΄ κ΄κ³λ₯Ό Springμ΄ μλμΌλ‘ μ°κ²°
3. κ΄μ μ§ν₯ νλ‘κ·Έλλ° (AOP)
ν‘λ¨ κ΄μ¬μ¬λ₯Ό λͺ¨λννμ¬ μ½λμ μ€λ³΅μ μ€μ
4. MVC ν¨ν΄ μ§μ
μΉ μ ν리μΌμ΄μ κ°λ°μ μν Model-View-Controller ꡬ쑰 μ 곡
π« Spring Frameworkμ νκ³μ
μ€μ μ 볡μ‘μ±
- XML μ€μ νμΌμ 볡μ‘ν¨
- λ€μν μ€μ μ΅μ μΌλ‘ μΈν νμ΅ κ³‘μ μ¦κ°
λμ μ΄κΈ° νμ΅ λμ΄λ
- κ°λ μ΄ν΄λ₯Ό μν λ§μ νμ΅ μκ° νμ
- λ€μν κΈ°λ₯ νμ©μ μν κΉμ μ΄ν΄ μꡬ
μμ‘΄μ± κ΄λ¦¬μ μ΄λ €μ
- λΌμ΄λΈλ¬λ¦¬ κ° νΈνμ± λ¬Έμ
- λ²μ μΆ©λ ν΄κ²°μ 볡μ‘μ±
λ°°ν¬ νκ²½ ꡬμ±μ λ²κ±°λ‘μ
- λ³λμ μΉ μ ν리μΌμ΄μ μλ² νμ
- 볡μ‘ν λ°°ν¬ κ³Όμ
π― SpringBootμ ν΄κ²°μ±
μλ μ€μ (Auto Configuration)
@SpringBootApplication // μ΄ νλμ μ λ
Έν
μ΄μ
μΌλ‘ λͺ¨λ μ€μ μλ£!
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
λ΄μ₯ μλ²
- Tomcat, Jetty, Undertow λ±μ λ΄μ₯
- λ³λμ μλ² μ€μΉ μμ΄
java -jar
λͺ λ ΉμΌλ‘ μ€ν κ°λ₯
μμ‘΄μ± κ΄λ¦¬ κ°μν
<!-- κΈ°μ‘΄ Spring Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.21</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.21</version>
</dependency>
<!-- ... μλ§μ μμ‘΄μ±λ€ -->
<!-- SpringBoot Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
μ΄μ νκ²½ μ§μ
- Health Check μλν¬μΈνΈ
- Metrics μμ§
- μΈλΆ μ€μ κ΄λ¦¬ (application.properties/yml)
ποΈ SpringBootμ ν΅μ¬ κ°λ
Starter Dependencies
λͺ©μ λ³λ‘ νμν μμ‘΄μ±μ λ¬Άμ΄μ μ 곡:
-
spring-boot-starter-web
: μΉ μ ν리μΌμ΄μ κ°λ° -
spring-boot-starter-data-jpa
: JPAλ₯Ό μ΄μ©ν λ°μ΄ν° μ‘μΈμ€ -
spring-boot-starter-security
: 보μ κΈ°λ₯ -
spring-boot-starter-test
: ν μ€νΈ νκ²½
νλ‘νμΌ (Profiles)
νκ²½λ³ μ€μ κ΄λ¦¬:
# application-dev.yml
server:
port: 8080
logging:
level:
com.example: DEBUG
# application-prod.yml
server:
port: 80
logging:
level:
com.example: INFO
π κ²°λ‘
Spring Frameworkλ μλ° μνκ³μ ν΅μ¬ νλ μμν¬λ‘μ κ°λ ₯ν κΈ°λ₯μ μ 곡νμ§λ§, 볡μ‘ν μ€μ κ³Ό λμ νμ΅ κ³‘μ μ΄λΌλ λ¨μ μ΄ μμμ΅λλ€.
SpringBootλ μ΄λ¬ν λ¬Έμ μ λ€μ ν΄κ²°νμ¬:
- β‘ λΉ λ₯Έ κ°λ° μμ: μ΅μνμ μ€μ μΌλ‘ νλ‘μ νΈ μμ
- π§ μλ ꡬμ±: κ΄λ‘λ₯Ό λ°λ₯΄λ μ€μ μλν
- π¦ κ°νΈν λ°°ν¬: λ΄μ₯ μλ²λ‘ λ¨λ μ€ν κ°λ₯
- π οΈ μμ°μ± ν₯μ: λΉμ¦λμ€ λ‘μ§μ μ§μ€ κ°λ₯
Spring μνκ³λ Spring Framework, SpringBoot, κ·Έλ¦¬κ³ λ€μν μλΈ νλ‘μ νΈλ€μ΄ ν¨κ» ꡬμ±νλ μμ±λ λμ κ°λ° νκ²½μ μ 곡ν©λλ€.
π λ μμ보기
곡μ λ¬Έμ: spring.io
βSpring makes programming Java quicker, easier, and safer for everybody. Springβs focus on speed, simplicity, and productivity has made it the worldβs most popular Java framework.β