본문 바로가기

Development/Web & Server

[Spring Framework] Scheduled 설정 & 사용

Spring3 에서 Scheduled 사용하는 방법이다.


우선 추가해야 될 사항으로 xmlns:task="http://www.springframework.org/schema/task"

 xsi:schemaLocation에는 http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd 을 추가해야 한다.


그리고 마지막으로는 아래의 것을 추가한다.


<task:annotation-driven/> 

<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:task="http://www.springframework.org/schema/task"

xmlns:context="http://www.springframework.org/schema/context"

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.0.xsd">


<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->

<annotation-driven />

<task:annotation-driven/>


<resources mapping="/resources/**" location="/resources/" />


<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<beans:property name="prefix" value="/WEB-INF/views/" />

<beans:property name="suffix" value=".jsp" />

</beans:bean>

<context:component-scan base-package="패키지" />

</beans:beans>


사용방법


@Scheduled(cron = "0 2/5 * * * *") public void harvestStatus() { ~~~~~~~~~~ }