반응형
1. Profile의 활용 방법
@Profile("prod")
@Configuration
public class BaseConfiguration {
@Bean
public String hello(){
return "hello";
}
}
-> prod 라는 profile 일 때만 빈을 사용가능함
@Component
public class SampleRunner implements ApplicationRunner {
@Autowired
private String hello;
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("====================");
System.out.println(hello);
System.out.println("====================");
}
}
SampleRunner.java
-> profile 설정이 없기 때문에 오류가 난다
2. 어떤 profile을 활성화시킬 것인가?
spring.profiles.active = prod
-> application.properties에 이렇게 설정해주면 실행 가능
java -jar target/spring-application-0.0.1-SNAPSHOT.jar --spring.profiles.active=test
[ terminal ]
-> 커맨드라인 아규먼트가 application.properties 보다 우선순위가 높기 때문에 test 가 실행된다.
3. 어떤 profile을 추가할 것인가? 프로파일용 프로퍼티
spring.profiles.include=proddb
application.properties
- application-proddb.properties 라는 파일 만들어서
naeun.fullName=dbdbdb 으로 설정해주면 profile이 추가가 됨
4. 매번 패키징하기 귀찮을 때
-> Program arguments 에 --spring.profiles.active=prod 라고 설정해주고 IDE에서 실행시킴
반응형
'Programming > Spring' 카테고리의 다른 글
스프링 레퍼런스 3장) Bean, BeanFactory, ApplicationContext (0) | 2020.10.26 |
---|---|
활용 6) 로깅(logging) 커스터마이징 (0) | 2020.10.11 |
활용 4) 외부 설정 : 타입 세이프 프로퍼티 @ConfigurationProperties (0) | 2020.10.11 |
활용 3) 외부설정 : application.properties (0) | 2020.10.11 |
기초 1) 스프링 빈(Bean) (0) | 2020.10.10 |