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
- Linux
- 자바기초스터디
- 파이썬
- 오류
- Oralce
- 시즌1
- 서울복층에어비앤비
- 8kyu
- https
- 6kyu
- 이클립스
- class파일바로보기
- Codewars
- 남산타워뷰
- CentOS
- 7kyu
- CentOS8
- monthPicker
- SQL
- 멀티쓰레드프로그래밍
- 이것이리눅스다
- 중첩쿼리
- JavaScript
- Python
- 사용자변경
- Eclipse
- VMware
- java
- 서울에어비앤비
- 주민번호마스킹
Archives
- Today
- Total
보통사람
Spring Boot Quartz 연동 예제 본문
환경설정
개발툴 : InteliJ
Spring Boot : 2.7.14
Quartz : 2.3.2
Java : 11
Gradle
1. bulid.gradle 파일에 추가
implementation "org.springframework.boot:spring-boot-starter-quartz"
2. @Scheduled 어노테이션을 이용
스케쥴러를 적용할 메소드에 @Scheduled 어노테이션을 사용한다.
@Controller
public class QuartzController {
@Scheduled(cron = "0/5 * * * * ?")
public void everyFiveSeconds() {
DateTimeFormatter patten = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formatDt = patten.format(LocalDateTime.now());
System.out.println(formatDt);
}
}
@SpringBootApplication이 붙은 파일에 @EnableScheduling 어노테이션 추가한다.
추가 하지 않으면 스케쥴러가 실행되지 않는다.
@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@EnableScheduling
스케쥴러를 기능을 켜는 역할을 하며, @Scheduled 어노테이션을 찾아서 실행을 시킨다.
Enables Spring's scheduled task execution capability, similar to functionality found in Spring's XML namespace.
This enables detection of @Scheduled annotations on any Spring-managed bean in the container.
EnableScheduling (Spring Framework 6.0.11 API)
Enables Spring's scheduled task execution capability, similar to functionality found in Spring's XML namespace. To be used on @Configuration classes as follows: @Configuration @EnableScheduling public class AppConfig { // various @Bean definitions } This e
docs.spring.io
3. 실행 결과
5초마다 실행 된것을 확인 할 수 있다.