설 연수
하하호홓
설 연수
전체 방문자
오늘
어제
  • 분류 전체보기 (231)
    • Back-End (2)
      • Java (20)
      • JSP (13)
      • Spring (18)
      • Kotlin (0)
      • node.js (0)
    • Front-End (68)
      • JavaScript (19)
      • jQuery (39)
      • Angular (4)
      • HTML (5)
    • Dev-Ops (12)
      • Linux, Cloud (5)
      • docker, k8s (5)
      • ElasticSeach (2)
    • Other (33)
      • OOP (3)
      • 알고리즘 (2)
      • DB (12)
      • Git (1)
      • Swift (4)
    • Backup (65)

블로그 메뉴

    공지사항

    인기 글

    태그

    • MYSQL
    • jquery invalid
    • flex
    • page not found
    • CORS
    • Redis
    • RESTful
    • 크로스도메인
    • angular4
    • Angular
    • angular callback
    • INVALID
    • docker
    • Kafka
    • mongodb
    • angular 콜백
    • jOOQ
    • 404 error
    • 패스트캠퍼스
    • angular2

    최근 댓글

    최근 글

    티스토리

    hELLO · Designed By 정상우.
    설 연수

    하하호홓

    Back-End/Spring

    스프링에서 Quartz 를 사용하여 잡스케줄링 하기 [출처] [본문스크랩] 스프링에서 Quartz 를 사용하여 잡스케줄링 하기|작성자 onandme

    2012. 8. 17. 13:17

    출처 제너럴의 프로그래밍 스토리 | GENERAL
    원문 http://blog.naver.com/minis24/80105686382

    스프링에서 쿼츠 잡스케줄링을 하는데 필요한 코드는 대부분 스프링 설정파일에 있다.

     

    애플리케이션에서는 컨텍스트 파일을 로딩하기만 하면 스프링이 설정을 읽어서 스케줄러를 자동으로 실행한다. ^^

     

    [ex: applicationContext_quartz.xml]

     <?xml version="1.0" encoding="EUC-KR"?>

     <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

     
     <bean id ="job" class="org.springframework.scheduling.quartz.JobDetailBean">
      <property name="jobClass" value ="com.bw.scheduler.QuartzJob"></property>
      <property name="jobDataAsMap">
       <map>
        <entry key="message" value ="this is a message from the Spring config file!!!"></entry>
       </map>
      </property>
     </bean> 

    ※ JobDetailBean 은 <bean> 태그의 id 를 잡 이름으로 사용하고,스케줄러의 기본 그룹을 그룹이름으로 사용한다.

        JobDataAsMap 속성을 사용하여 JobDataMap에 데이터를 추가 할 수 있다.
     

     


     <bean id ="SimpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
      <property name="jobDetail" ref ="job"></property>
      <property name="startDelay" value ="1000"></property>
      <property name="repeatInterval" value ="3000"></property>
      <property name="jobDataAsMap">
       <map>
        <entry key="triggerMessage" value ="trigger message from the Spring config file!!!"></entry>
       </map>
      </property>
     </bean> 

    ※ 스프링에서는 SimpleTrigger클래스를 감싼 SimpleTriggerBean 과 CronTrigger클래스를 감싼

       CronTriggerBean을 제공하여 설정파일에서 선언적인 방법으로 JobDetailBean 과 연결할 수 있다.  

     

    <bean id ="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
      <property name="jobDetail" ref ="job"></property>
      <property name="cronExpression" value ="3/5 * 14,15,16,17 * * ?"></property>
      <property name="jobDataAsMap">
       <map>
        <entry key="triggerMessage" value ="cronTrigger message from the Spring config file!!!"></entry>
       </map>
      </property>
     </bean>

     


     <bean id ="schedulerFactory" class ="org.springframework.scheduling.quartz.SchedulerFactoryBean">
      <property name="triggers" >
       <list>
        <ref local="simpleTrigger"></ref>
        <ref local="cronTrigger"></ref>
       </list>
      </property>
     </bean>
     
    </beans>

     

    [ex:스케줄러 실행]

     import org.springframework.context.ApplicationContext;
     import org.springframework.context.support.ClassPathXmlApplicationContext;

     

     public class TimerFactoryBean {
         public static void main(String[] args){
      
             String[] src = new String[]{"classpath:com/bw/config/applicationContext_quartz.xml"};
             ApplicationContext ctx = new ClassPathXmlApplicationContext(src);
      
         }
    }

    [출처] [본문스크랩] 스프링에서 Quartz 를 사용하여 잡스케줄링 하기|작성자 onandme

    http://blog.naver.com/onandme/110096009077

    저작자표시 (새창열림)

    'Back-End > Spring' 카테고리의 다른 글

    @RequestParam - 1:1로 파라미터 집어넣기  (0) 2012.09.11
    @ModelAttribute - 파라메터 한번에 집어넣기  (0) 2012.09.11
    기술에 독립적인 DAO를 만들기 위한 DataAccessException  (0) 2012.07.23
    SpringMVC에서 간단한 ExceptionResolver 구성하기  (0) 2012.06.26
    스프링에서 Content Type별 View 자동 맵핑 하기  (0) 2012.06.26
      'Back-End/Spring' 카테고리의 다른 글
      • @RequestParam - 1:1로 파라미터 집어넣기
      • @ModelAttribute - 파라메터 한번에 집어넣기
      • 기술에 독립적인 DAO를 만들기 위한 DataAccessException
      • SpringMVC에서 간단한 ExceptionResolver 구성하기
      설 연수
      설 연수

      티스토리툴바