반응형

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에서 실행시킴

반응형

+ Recent posts