1. webapp -> WEB-INF -> spring -> appServlet -> servlet-context.xml 이동
2. beans 태그 안과 그 밖에 아래 빨간색으로 표기한 것을 추가.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<task:annotation-driven />
3. java 클래스를 만든다.
ex ) com.test.scheduler
package com.test.scheduler;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* wifi 상태를 체크하는 스케줄러
* @author 임성진
*
*/
@Component
public class WifiStateScheduler {
/**
* 5초 주기로 검사한다.
*/
@Scheduled(fixedRate=5000)
public void cronTest1() {
System.out.println("5초 뒤에 실행됩니다. ");
}
}
4. 실행해보면 "5초 뒤에 실행됩니다."가 출력된 것을 볼 수 있다.
'Programming > Spring' 카테고리의 다른 글
log4j.xml 파일 로그 쌓기 (0) | 2017.03.08 |
---|---|
[Spring] 에러 코드 관리하기(Enum) (0) | 2017.02.24 |
Multiple Contexts have a path of 'project name' (0) | 2016.12.22 |
외부 URL으로 이미지 접근하기 (0) | 2016.12.16 |
Update SVN Cache. (0) | 2016.12.16 |