[Spring] 설정 파일 따로 사용

이다혜·2023년 11월 30일
0

Spring

목록 보기
19/27

스프링에서는 환경별로 설정 파일을 따로 사용할 수 있다.

1. 기본 설정 파일

일반적으로 application.yml 파일이 기본 설정 파일이다.
여기에는 모든 환경에서 공통적으로 사용되는 설정이 들어간다.

server:
  port: 8080

database:
  url: jdbc:mysql://localhost:3306/myapp
  username: root
  password: secret

2. 환경별 설정 파일

{profile}.yml 형식이어야 한다.

application-dev.yml(개발 환경 설정)

database:
  url: jdbc:mysql://dev-db-server:3306/myapp
  username: devuser
  password: devsecret

application-test.yml(테스트 환경 설정)

database:
  url: jdbc:mysql://test-db-server:3306/myapp
  username: testuser
  password: testsecret

3. @Profile

@Profile 어노테이션을 사용하여 특정 프로파일에서만 활성화되도록 지정할 수 있다.

@SpringBootTest
@ActiveProfiles("test")
class Sb231130ApplicationTests {
	...
}

0개의 댓글