스프링에서는 환경별로 설정 파일을 따로 사용할 수 있다.
일반적으로 application.yml
파일이 기본 설정 파일이다.
여기에는 모든 환경에서 공통적으로 사용되는 설정이 들어간다.
server:
port: 8080
database:
url: jdbc:mysql://localhost:3306/myapp
username: root
password: secret
{profile}.yml
형식이어야 한다.
database:
url: jdbc:mysql://dev-db-server:3306/myapp
username: devuser
password: devsecret
database:
url: jdbc:mysql://test-db-server:3306/myapp
username: testuser
password: testsecret
@Profile
어노테이션을 사용하여 특정 프로파일에서만 활성화되도록 지정할 수 있다.
@SpringBootTest
@ActiveProfiles("test")
class Sb231130ApplicationTests {
...
}