[Spring Boot] Spring Profile 따른 환경 설정

Posted by 김성철

Spring Profile 따른 환경 설정

https://galid1.tistory.com/664  
  
개발, 테스트, 운영 환경에따라서  
DB정보, 포트 정보등이 변경되야 할때가 있음  
이때마다 해당 정보들을 변경하거나 주석처리 하는 일이 많으면 안되기떄문에 사용함  
  
application.yml 파일에서 상단에 아래와 같이 작성하였고,  
active 이부분만 수정해주면 이제 모든 설정이 변경될거임  
  
--- 는 구분자로 나눠주는 역할을 함  
  
  profiles: local 이부분은 이제 active에서 사용할 설정프로파일명이라고 보면됨  
  
=================================================================================================================  
spring :  
  profiles :  
	active : test  
---  
  
spring :  
  profiles: local  
  session :  
	timeout: 600  
  datasource:  
	driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy  
	url: jdbc:log4jdbc:mysql://localhost:3306/stock?serverTimezone=UTC&characterEncoding=UTF-8  
	username: sungchul  
	password: sungchul1234  
  
server :  
  port : 80  
  session:  
	timeout : 600  
mybatis:  
  configuration:  
	map-underscore-to-camel-case: true  
	call-setters-on-nulls: true  
	jdbc-type-for-null: null  
---  
  
spring :  
  profiles: test  
  session :  
	timeout: 600  
  datasource:  
	driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy  
	url: jdbc:log4jdbc:mysql://localhost:3306/stock?serverTimezone=UTC&characterEncoding=UTF-8  
	username: sungchul  
	password: sungchul1234  
  
server :  
  port : 8080  
  session:  
	timeout : 600  
  
mybatis:  
  configuration:  
	map-underscore-to-camel-case: true  
	call-setters-on-nulls: true  
	jdbc-type-for-null: null  
=================================================================================================================