Spring Boot 환경 프로퍼티 나누기 (Dev/Test/Prod 등)

지난 글을 보면 Spring Boot와 MySQL을 연동했다.

MySQL을 사용하도록 설정

/resources/application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/{DB}?autoReconnect=true 
spring.datasource.username={USER NAME}
spring.datasource.password={PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

보통 DB연결은 실제 서버와 로컬 서버의 설정은 다르게 된다.

나는 간단하게 Dev와 Prod으로 나누어보려고 한다.

방법은 간단하게 application-{env}.properties 파일을 생성하면 된다.

application-{env}.properties 파일 생성

/resources/

test 환경까지 추가하려면 application-test.properties 파일도 생성

application.properties에 운용할 환경 설정

application.properties에는 어느 환경인지 설정을 넣어준다.

spring.profiles.active=dev

또한, 공통적으로 사용할 설정을 넣어주어도 된다.

설정 확인

위와 같이 설정하고 서버를 실행하면 해당 환경에서 실행이 되는 것을 확인할 수 있다.

Dev 프로필이 활성화 된 것을 확인할 수 있다.
아무것도 설정하지 않았을 때

답글 남기기