728x90
SMALL
스케줄러 service를 하나 만들어주자
package business.com.api;
import org.springframework.stereotype.Service;
@Service
public class SchedulerService {
public void scheduleRun(){
System.out.println("조금 떨린다...");
}
}
나는 context-scheduler.xml를 하나 만들어서 이 안에 cron설정을 했다
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<bean id="apiScheduleService" class="business.com.api.SchedulerService" />
<task:scheduler id="gsScheduler" pool-size="10" />
<task:executor id="gsTaskExecutor" pool-size="10" />
<task:annotation-driven executor="gsTaskExecutor"
scheduler="gsScheduler" />
</beans>
package business.com.api;
//추가//
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class SchedulerService {
//추가//
@Scheduled(cron="*/30 * * * * *")
public void scheduleRun(){
System.out.println("조금 떨린다...");
}
}
scheduled 어노테이션을 추가해주고 크론을 설정해준다
30초마다 한번씩 조금 떨리는 메시지를 날려보자..
잘 뜨네예...
기본 설정완료
여기서 이제 원하는 로직을 추가해주면된다
728x90
LIST
'JAVA > Java' 카테고리의 다른 글
java다운로드, 시스템 환경변수 설정, java 버전 확인 (0) | 2023.03.29 |
---|---|
session과 Httpsessionlistener (0) | 2022.10.25 |
web.xml의 element(context-param,filter) (0) | 2022.08.09 |
java list<map<string,object>>에서 키값 value값 찾기 (0) | 2022.05.24 |
java list에서 key값 뽑기, list를 map으로 만들기 (0) | 2022.05.24 |
댓글