프로젝트에서 여러개의 설정 파일 존재할 때(application.properties)

Chooooo·2023년 11월 3일
0

인턴생활

목록 보기
6/19

실제 현업에서 application.properties 설정 파일은 resources 하위에 real, develop, stage 3개의 세팅으로 실행하고 있었다.

그래서 전부 spring.profiles.active 설정이 각각 본인으로 되어 있길래, 어떻게 실행을 하면 real로 바로 돌아가는지 궁금했다.

  • 답은 main에서 설정하던가, 따로 환경 설정을 해주면 된다는 것이다..

main에서 설정

    public static void main(String[] args) {

        String profile = System.getProperty("spring.profiles.active");
        if(profile == null) {
            System.setProperty("spring.profiles.active", "develop");
        }
        SpringApplication.run(AdminApplication.class, args);
    }

이런 식으로 메인에서 직접 세팅을 하고 돌리면 된다.

환경 설정

근데 만약 이래도 다른 설정파일이 돌아간다면!!!

인텔리제이 상단에 Run > Edit Configurations > Environment 하위에서 Vm Options 안에 넣어줘야 한다.

-Dspring.profiles.active=develop 이런 식으로 내가 돌리고자 하는 active를 입력해서 실행하면 해당 설정파일로 실행하게 된다.

이렇게 해서 원하는 설정파일을 돌리면 된다!!!

profile
back-end, 지속 성장 가능한 개발자를 향하여

0개의 댓글