스프링
[Spring] application.properties 또는 application.yml 파일에 미리 값을 지정해둔 다음 사용하기
nan2
2022. 3. 29. 09:38
반응형
- application.yml ( application.properties ) 파일
my-host-id: xxx.xxx.xxxx
schedule:
/* 10분 간격으로 03분, 13분, 23분, 33분, 43분, 53분 실행 */
TestBatch: 0 3/10 * * * *
-----------------------------------------------------------------
my-host-id=xxx.xxx.xxxx
schedule.TestBatch=0 3/10 * * * *
- 속성 값을 사용하는 class
@Slf4j
@RequiredArgsConstructor
@Component
public class TestBatch{
@Value("${my-host-id}")
private String hostId;
@Scheduled(cron="${schedule.TestBatch}")
public void scheduled(){
...
}
application.properties 또는 application.yml 파일에 원하는 값을 지정한 다음
사용할 때는 "${ properties 이름 }" 으로 사용한다.
반응형