@Value
폴더구조
application.yml
property:
test:
name: property depth test
propertyTest: test
propertyTestList: a,b,c
이제 변수에 yml파일에 저장돼있는 값을 매핑시켜보자.
AutoconfigurationApplicationTests.java
@Value("${property.test.name}")
private String propertyTestName;
@Value("${propertyTest}")
private String propertyTest;
@Value("${propertyTestList}")
private List<String> propertyTestList;
@Value("${propertyTestList}")
private String[] propertyTestArray;
@Value("#{'${propertyTestList}'.split(',')}")
private List<String> propertyTestListSplit;
@Test
public void testValue(){
log.info("==================================================");
log.info(propertyTestName);
log.info(propertyTest);
log.info(propertyTestList.toString());
log.info(Arrays.toString(propertyTestArray));
log.info(propertyTestListSplit.toString());
}
결과.
2019-08-16 21:32:32.930 INFO 1970 --- [ Test worker] c.e.d.AutoconfigurationApplicationTests : property depth test
2019-08-16 21:32:32.930 INFO 1970 --- [ Test worker] c.e.d.AutoconfigurationApplicationTests : test
2019-08-16 21:32:32.930 INFO 1970 --- [ Test worker] c.e.d.AutoconfigurationApplicationTests : [a, b, c]
2019-08-16 21:32:32.930 INFO 1970 --- [ Test worker] c.e.d.AutoconfigurationApplicationTests : [a, b, c]
2019-08-16 21:32:32.930 INFO 1970 --- [ Test worker] c.e.d.AutoconfigurationApplicationTests : [a, b, c]
'JAVA > SPRING' 카테고리의 다른 글
[spring security]레거시 프로젝트에 스프링 시큐리티를 적용해보자.(1) (0) | 2019.09.14 |
---|---|
[SPRING] 스프링부트 테스트관련 어노테이션 정리 (0) | 2019.08.16 |
[SPRING] web.xml 보충설명 (0) | 2019.08.10 |
[SPRING] .properties 에서 값 가져오기. (0) | 2019.08.08 |
[SPRING] 스프링 IoC컨테이너 (6) | 2019.08.07 |