티스토리 뷰

웹개발이야기/JAVA

spring scheduler 등록하기

최고다님 2016. 12. 6. 18:20

Web 응용프로그램들을 개발하다보면 항상 스케쥴 관련으로 무언가를 해야 할 때가 있는데

프로그램 제작은 귀찮고.. 셋팅도 귀찮고.. 그렇다면 그냥 기존 프로젝트에다가 스케쥴러를 만들어 버리자!


StaticsSchedule.java

@Component

public class StaticsSchedule {

    private static final Logger LOGGER = LoggerFactory.getLogger(StaticsSchedule.class);

    //매일 오전 8시 30분 실행

    @Scheduled(cron = "0 30 8 * * *")

    public void staticsCount()

    {

        try {

        LOGGER.info("통계 관련 1일 스케쥴러 실행");

        //To-do

        } catch (Exception e) {

        LOGGER.error("통계 관련 1일 스케쥴러 에러");

            e.printStackTrace();

        }

    }

}


dispatcher-servlet.xml

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

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

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

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

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

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

xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd

">

    <!-- 스케쥴러 -->

    <bean id="staticsSchedule " class="com.commom.Scheduler.StaticsSchedule" />

    <task:scheduler id="gsScheduler" pool-size="10" />

    <task:executor id="gsTaskExecutor" pool-size="10" />

    <task:annotation-driven executor="gsTaskExecutor" scheduler="gsScheduler" />

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함