스프링 부트 설정
generate 해서 만들어진 파일을 압축해제 한 후 IDE로 폴더를 연다.
https://mvnrepository.com/artifact/org.awaitility/awaitility/4.2.0 에 있는 dependency를 복사해 pom.xml에 dependencies에 붙여넣는다.
src\main\java\com\example\demo 에 ScheduledTasks.java 클래스 파일을 생성하고 slf4j 라이브러리를 사용해 5초마다 콘솔 창에 지금 시간이 몇시인지 출력하는 코드를 작성한다.
ScheduledTasks에 @Component Anootaion을 사용해 빈으로 등록하고 @Scheduled Anotation을 사용해 몇초마다 특정 메서드를 실행할것인지를 결정한다.
https://www.slf4j.org/manual.html
SLF4J Manual
SLF4J user manual The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and reload4j. SLF4J allows the end-user to plug in the desired logging framework at dep
www.slf4j.org
https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/text/SimpleDateFormat.html
SimpleDateFormat (Java SE 19 & JDK 19)
All Implemented Interfaces: Serializable, Cloneable SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date → text), parsing (text → date), and normalization. SimpleDateFormat a
docs.oracle.com
src\main\java\com\example\demo\DemoApplication.java에 @EnableScheduling Anotation을 붙여 만들어둔 ScheduledTasks가 실행되도록 한다.
이제 만들어진 SpringApplication을 실행하면 5초마다 시간이 콘솔창에 출력되는 것을 확인 할 수 있다.
참고 사이트 [https://spring.io/guides/gs/scheduling-tasks/]
'Spring' 카테고리의 다른 글
jjwt 서버 적용 오류 (0) | 2023.06.12 |
---|---|
스프링 DATA JPA와 Mysql 사용 시 원하는 표기법으로 컬럼명 생성하기 (0) | 2023.05.13 |
Requesting Java AST from selection 오류 해결법 (0) | 2023.03.11 |
Restful web service 만들기 (0) | 2023.02.01 |
스프링 부트를 이용해 웹서버 구축하기 (0) | 2023.01.30 |