Spring Framework์์ ์ ๊ณตํด์ฃผ๋ ๊ธฐ๋ฅ์ด๋ค.
ํน์ ํ ํ๋ก ํ์ผ์์๋ง ํน์ ํ ๋น์ ๋ฑ๋กํ๊ณ ์ถ๋ค๊ฑฐ๋
์ ํ๋ฆฌ์ผ์ด์ ์ ๋์์ ํน์ ํ ํ๋กํ์ผ์์ ๋น ์ค์ ์ ๋ค๋ฅด๊ฒ ํ๊ณ ์ถ์ ๋ ์ด๋ค.
@Profile
@Profile("prod") // ์ค์ ํ์ผ ์์ฒด๊ฐ "prod"๋ผ๋ ํ๋กํ์ผ์ผ ๋ ์ฌ์ฉ๋๋ค. ๊ทธ๋ฌ๋๊น ๋น์ฐํ hello ๋น๋ ๋ชป์ด๋ค.
@Configuration
public class BaseConfiguration {
@Bean
public String hello(){
return "hello";
}
}
@Profile("test") // ์ค์ ํ์ผ ์์ฒด๊ฐ "test"๋ผ๋ ํ๋กํ์ผ์ผ ๋ ์ฌ์ฉ๋๋ค.
@Configuration
public class TestConfiguration {
@Bean
public String hello(){
return "hello test";
}
}
spring.profiles.active
์ด๋ค ํ๋กํ์ผ์ ํ์ฑํํ ๊ฒ์ธ์ง ์ง์ ํ๋ค.
[ application.properties ]
spring.profiles.active=test
jueun.name=JUEUN
application-{profile}.properties
ํ๋กํ์ผ์ฉ ํ๋กํผํฐ ํ์ผ์ ์ฐ์ ์์๊ฐ ๊ธฐ๋ณธ์ ์ธ application.properties๋ณด๋ค ๋๋ค.
์ค๋ฒ๋ผ์ด๋ฉํ๋ค๋ ๋ป์ด๋ค.
์์ 1
[ application-test.properties ]
jueun.name=jueun test
JUEUN ์ด ์๋ jueun test๊ฐ ์ถ๋ ฅ๋๋ค.
application.properties์์ ์ด ์ ํ๋ฆฌ์ผ์ด์ ์คํ์ ์ฌ์ฉํ ํ๋กํ์ผ์ spring.profiles.active=test๋ก ์ค์ ํ๊ธฐ ๋๋ฌธ์ @Profile("test") ์ค์ ์ด ์ ์ฉ๋๊ณ @ConfigurationProperties("jueun") ์ ํด๋น ์ค์ ์ ๋น์ด ์ฃผ์ ๋์ด jueun test๊ฐ ์ถ๋ ฅ๋ ๊ฒ์ด๋ค.
์์ 2
[ application-prod.properties ]
jueun.name=jueun prod
program arguments ์ --spring.profiles.active=prod ์ ๋ ฅํ์ฌ ์คํํ๊ฑฐ๋
ํฐ๋ฏธ๋์์ ๋น๋ ํ java -jar target/demo-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod ์คํํ๋ฉด
jueun prod๊ฐ ์ถ๋ ฅ๋๋ค.
'Springboot' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[spring boot] ๋ก๊ฑฐ๋ฅผ Log4j2๋ก ๋ณ๊ฒฝํ๊ธฐ (0) | 2021.01.08 |
---|---|
[spring boot] logging ์ปค์คํฐ๋ง์ด์ง (0) | 2021.01.08 |
[spring boot] logging ๊ธฐ๋ณธ ์ค์ (0) | 2021.01.08 |
[spring boot] ์ธ๋ถ ์ค์ (0) | 2021.01.08 |
SpringApplication (0) | 2021.01.06 |
์คํ๋ง๋ถํธ, ๋ ๋ฆฝ์ ์ผ๋ก ์คํ ๊ฐ๋ฅํ JAR (0) | 2021.01.06 |