[07] Profiles

MIIINΒ·2021λ…„ 10μ›” 2일
0

Spring Boot

λͺ©λ‘ 보기
7/9
post-thumbnail

πŸ“ Spring Profiles

Spring Profiles은 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 섀정을 λ”°λ‘œ λΆ„λ¦¬ν•˜λŠ” 방법을 μ œκ³΅ν•˜κ³  νŠΉμ •ν•œ ν™˜κ²½μ—μ„œλ§Œ μž‘λ™ν•  수 있게 ν•΄μ€€λ‹€. @Component, @Configuration, @ConfigurationProperties μ–΄λ…Έν…Œμ΄μ…˜μ€ μ–΄λ–€ profile을 λΆˆλŸ¬μ˜¬μ§€ @Profile μ–΄λ…Έν…Œμ΄μ…˜μœΌλ‘œ ν‘œμ‹œν•  수 μžˆλ‹€.

@Configuration(proxyBeanMethods = false)
@Profile("production")
public class ProductionConfiguration {

    // ...

}

πŸ”… Active Profiles

μ–΄λ–€ profile듀을 ν™œμ„±ν™”ν• μ§€ spring.profiles.active ν™˜κ²½ 속성을 지정할 수 μžˆλ‹€.

// application.properties
spring.profiles.active=dev,hsqldb

// shell
$ java -jar myproject.jar --spring.profiles.active=dev,hsqldb

// java
SpringApplication.setAdditionalProfiles(…)

ν™œμ„±ν™”λœ profile이 μ—†μœΌλ©΄ default profile이 μ‚¬μš©λœλ‹€. spring.profiles.default ν™˜κ²½ μ†μ„±μœΌλ‘œ default profile λͺ…을 λ°”κΏ€ 수 μžˆλ‹€.

spring.profiles.default=none

πŸ”… Profile Groups

μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— μ •μ˜ν•˜κ³  μ‚¬μš©ν•œ profile듀은 λ„ˆλ¬΄ μ„ΈλΆ„ν™”λ˜μ–΄ μ‚¬μš©ν•˜κΈ°μ— 번거둜운 κ²½μš°κ°€ μžˆλ‹€. 예λ₯Ό λ“€μ–΄, λ°μ΄ν„°λ² μ΄μŠ€μ™€ λ©”μ‹œμ§• κΈ°λŠ₯을 μ‚¬μš©ν•˜λ„λ‘ ν•˜λŠ” proddb와 prodmq profile듀을 κ°€μ§ˆ 수 μžˆλ‹€. Spring BootλŠ” profile 그룹을 μ •μ˜ν•  수 있고, κ΄€λ ¨ ν”„λ‘œνŒŒμΌ 그룹의 논리적 이름을 μ •μ˜ν•  수 μžˆλ‹€.

spring.profiles.group.production[0]=proddb
spring.profiles.group.production[1]=prodmq

πŸͺ λ‹€μŒμœΌλ‘œ ν”„λ‘œκ·Έλž˜λ°μ— μ—†μ–΄μ„œλŠ” μ•ˆλ  λ‘œκΉ…μ— λŒ€ν•΄ μ•Œμ•„λ³΄μž~

profile
λ°±μ—”λ“œκ°œλ°œμž

0개의 λŒ“κΈ€