반응형
다중 프로파일 적용 하는 방법
1.env file example
# application-one.yml
spring:
profiles.include:
- two # 포함시킬 프로파일
- three # 포함시킬 프로파일
same:
who: I am one # 중복되는 프로퍼티
diff: # 중복되지 않는 프로퍼티
one: 1111
--------------------------------------------
# application-two.yml
same: # 중복되는 프로퍼티
who: I am two
diff: # 중복되지 않는 프로퍼티
two: 2222
# application-three.yml
same: # 중복되는 프로퍼티
who: I am three
diff: # 중복되지 않는 프로퍼티
three: 3333
2.Spring profile 적용Test 코드
package com.example.test.SpringBootApplication;
import org.springframework.beans.factory.annotation.Value;
import javax.annotation.PostConstruct;
@SpringBootApplication
public class SpringBootApplication {
@Value("${same.who}")
private String whoAmI;
@Value("${diff.one}")
private String one;
@Value("${diff.two}")
private String two;
@Value("${diff.three}")
private String three;
public static void main(String[] args) {
SpringApplication.run(EssApplication.class, args);
}
@PostConstruct
public void print() {
System.out.println("Who are you :" + whoAmI);
System.out.println("One properties - " + one);
System.out.println("Two properties - " + two);
System.out.println("Three properties - " + three);
}
}
3. 실행
java -jar App.jar --spring.profiles.active=one,two
4.결과
반응형
'개발 > Spring Boot' 카테고리의 다른 글
[Spring Boot] ThreadPoolTaskExecutor란 (0) | 2023.10.24 |
---|---|
[Spring Boot] Linux에 Service 배포 (0) | 2023.10.11 |
[Spring Boot] Netflix zuul을 이용한 API ByPass (1) | 2023.10.11 |
[Spring Boot] ssl 인증서 적용 및 발급(Let's Encrypt ) (0) | 2023.10.11 |
[Spring Boot] war 패키징 방법 (0) | 2023.10.10 |