Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- tucker의 go 언어 프로그래밍
- AI
- Pinpoint
- Linux
- docker
- 기록으로 실력을 쌓자
- aws
- 오블완
- 공부
- golang
- 정보처리기사실기 기출문제
- CKA 기출문제
- kotlin querydsl
- kotlin coroutine
- Elasticsearch
- kotlin
- 정보처리기사 실기 기출문제
- AWS EKS
- CloudWatch
- Kubernetes
- go
- APM
- 티스토리챌린지
- PETERICA
- mysql 튜닝
- Spring
- 코틀린 코루틴의 정석
- CKA
- Java
- minikube
Archives
- Today
- Total
피터의 개발이야기
[Spring] Spring에서 환경변수를 배열로 가져오기 본문
반응형
Spring에서 환경변수를 배열로 불러올 경우가 있습니다. 다중환변 변수를 리스트로 불러오는 방법을 정리하였습니다.
application.properties
# get the element as an array
base.module.elementToSearch=1,2,3,4,5,6
base.module.elementToSearch2=a;b;c;d;e;f
DemoController.java
@Value("${base.module.elementToSearch}")
private String[] elementToSearch;
@Value("#{'${base.module.elementToSearch2}'.split(';')}")
private String[] elementToSearch2;
@GetMapping("/elementAsArray")
@ApiOperation(httpMethod = "GET", value = "properties Array element Test", notes = "properties Test", tags = "테스트")
public String elementAsArray(){
// 1. 기본 쉼표로 Array 가져오기
for (String element : elementToSearch){
System.out.println(element);
}
// 2. ';'로 Array 가져오기
for (String element : elementToSearch2){
System.out.println(element);
}
return "suc";
}
첫번째는 기본 쉼표를 구분자로 Array를 가져옵니다.
두번쨰는 ';'를 구분자로 Array를 가져옵니다.
반응형
'Programming > Spring' 카테고리의 다른 글
[Spring] DTO 깔끔하게 정리하는 법, Inner Class (0) | 2021.03.02 |
---|---|
[Spring] 항상 동일한 데이터를 DB 호출하는 경우 Bean으로 데이터 생성하여 사용하기 (0) | 2021.02.01 |
[Spring] @JsonIgnore과 @Transient 차이 때문에 발생한 could not extract ResultSet 문제 (0) | 2021.01.25 |
[Spring] parallelStream, Intercom 데이터 백업하기 (0) | 2021.01.16 |
[Spring] JCenter란 (0) | 2021.01.15 |
Comments