Tech Stock logo Tech Stock

스프링부트에서는 application.yml을 여러개로 만들어서
환경마다 다르게 설정해서 사용할 수 있다.

src/main/resources


application-local.yml
application-test.yml
application-ec2.yml



밑에처럼 여러개를 만들고 실행할때 profile명에 지정해서 실행(Run config -> profile : 프로파일 지정명)
java로 실행할때는 이런식 하면됨

java -jar -Dspring.profiles.active=ec-2

src/main/resources/application-local.yml
  
##########################################
# Local용
##########################################

spring:
  profiles:
    active: local


src/main/resources/application-ec2.yml
  
##########################################
# AWS RDS용
##########################################

spring:
  profiles:
    active: ec-2



위의 방법이 기본인데. 혹시 에러 뜨면 이렇게 쓰자

src/main/resources/application-local.yml
  
##########################################
# Local용
##########################################

pring:
  config:
    activate:  
      on-profile: local


src/main/resources/application-ec2.yml

##########################################
# AWS RDS용
##########################################
spring:
  config:
    activate:  
      on-profile: ec-2