gnusraun

Egov Scheduler 설정 본문

Backend/Egov

Egov Scheduler 설정

gnusraun 2023. 5. 13. 17:12
728x90

Egov Scheduler 설정하기

 

 

:: pom.xml

 

<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>2.2.0</version>
</dependency>

 

 

:: context-scheduler.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-2.5.xsd">

	<!-- 컴포넌트 스캔 -->
	<context:component-scan base-package="egovframework.example.cmmn.batch"></context:component-scan>
	
	<!-- quartz 스케줄링 -->
	<bean id="schedulerJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<!-- 서비스 구현 객체의 빈 이름을 인자로 줍니다. (ServiceImpl(@Service("")) -->
		<property name="targetObject" ref="sayHelloService" /> 
		<!-- 서비스 객체에서 주기적으로 실행될 메소드른 지정합니다. (ServiceImpl(void method()))-->
		<property name="targetMethod" value="sayHello" />
		<!-- 동시 실행을 방지합니다. -->
		<property name="concurrent" value="false" />
	</bean>
	
	<!-- 트리거 -->
	<bean id="jobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail" ref="schedulerJob" />
		<!-- CronTrigger를 사용하여 2분 간격으로 실행되도록 지정했습니다. -->
		<property name="cronExpression" value="*/10 * * * * ?" />
	</bean>
	
	<!-- 스케줄러 실행 -->
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<!-- 앞에서 설정한 트리거를 등록합니다. 필요하면 여러개 만들어서 등록하면 됩니다. -->
			<list>
				<ref bean="jobTrigger" />
			</list>
		</property>
	</bean>

</beans>

 

 

:: SayHelloService.java

 

package egovframework.example.cmmn.batch;

public interface SayHelloService {

	public void sayHello();

}

 

 

:: SayHelloServiceImpl.java

 

package egovframework.example.cmmn.batch.impl;

import org.springframework.stereotype.Service;

@Service("sayHelloService")
public class SayHelloServiceImpl {
	
	public void sayHello() {
		System.out.println("배치스케줄러 정상적으로 동작 완료");
	}

}

 

 

출처 -  https://hyeounstory.tistory.com/84

728x90