외부 설정 파일 :설정 값들을 애플리케이션 안 또는 밖에 파일로 설정
● properties
● YAML
● 환경변수
● 커맨드 라인 아규먼트
ex)
Application.properties
dean.name = dean
이미 정의되어 있는 파일 안에 설정 하는 방법
@Value("${dean.name}")
과 같이 사용 할 수 있다.
application.properties 우선 순위 (높은게 낮은걸 덮어 씁니다.)
1. file:./config/
2. file:./
3. classpath:/config/
4. classpath:/
java -jar target/deanoh-0.0.1-SNAPSHOT.jar --dean.name=dean
DeanohApplicationTest.class
@RunWith(value = SpringRunner.class)
@SpringBootTest
class DeanohApplicationTests {
@Autowired
Environment environment;
@Test
void contextLoads() {
assertThat(environment.getProperty("dean.name"))
.isEqualTo("dean");
}
}
Test의 resources 파일 적용
dean.name = dean
dean.age = ${random.int} // 랜덤 사용
server.port = 0 // 서버는 0
src 에 프로퍼티 읽어서 빌드 후 test 에 프로퍼티를 오버라이드 한다.
src에 프로퍼티 생성.
@TestPropertySource(locations = "classpath:/test.propertise") 사용.