728x90
반응형
전자정부프레임워크에서 스케줄러 등록방법 까먹을지 몰라서 정리 차원에서...
WEN-INF\config\egovframework\springmvc\egov-com-scheduler.xml 파일을 생성후 필요한 스케줄러를 등록한다.
환경설정 시간 관련 기본정보는 globals.properties파일에 설정한다.
1. 스케줄러 처리 환경파일 설정 등록할 스케줄러가 여러개인 경우 하나씩 인터페이스를 정의한후에 스케줄러 트리거에 배열로 등록한다.
- egov-com-scheduler.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:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
<!-- 환경설정 기본정보를 globals.properties 에서 참조하도록 propertyConfigurer 설정 -->
<util:properties id="propertyConfigurer" location="classpath:/egovframework/egovProps/globals.properties"/>
<context:property-placeholder properties-ref="propertyConfigurer" />
<context:annotation-config />
<!-- 1. 관세청 통관정보 인터페이스 -->
<bean id="tnEntrInfoMScheduleService" class="egovframework.tibero.schedule.inter.service.TnEntrInfoMScheduleServiceImpl" />
<!-- 2. 코드마스터,코드상세 인터페이스 -->
<bean id="ncomCdMstrInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NcomCdMstrInterfaceScheduleServiceImpl" />
<!-- 3. 업체마스터 인터페이스 -->
<bean id="ncomCoMstrInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NcomCoMstrInterfaceScheduleServiceImpl" />
<!-- 4. 기관법정동 인터페이스 -->
<bean id="ncomGovInsttBizAreaMapInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NcomGovInsttBizAreaMapInterfaceScheduleServiceImpl" />
<!-- 5. 정부기관마스터 인터페이스 -->
<bean id="ncomGovInsttMstrInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NcomGovInsttMstrInterfaceScheduleServiceImpl" />
<!-- 6. ID마스터 인터페이스 -->
<bean id="ncomIdMstrInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NcomIdMstrInterfaceScheduleServiceImpl" />
<!-- 7. 품목마스터 인터페이스 -->
<bean id="ncomItemMstrInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NcomItemMstrInterfaceScheduleServiceImpl" />
<!-- 8. 법정동 인터페이스 -->
<bean id="ncomLawdInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NcomLawdInterfaceScheduleServiceImpl" />
<!-- 9. 휴일 인터페이스 -->
<bean id="nuciHldyInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.NuciHldyInterfaceScheduleServiceImpl" />
<!-- 10. 사용자기관업체관계 인터페이스 -->
<bean id="tnUserInsttEntrpsRInterfaceScheduleService" class="egovframework.tibero.schedule.inter.service.TnUserInsttEntrpsRInterfaceScheduleServiceImpl" />
<!-- 1.1 관세청 통관정보 Cron Quartz Scheduler -->
<bean id="tnEntrInfoCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.TnEntrInfoJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="tnEntrInfoMScheduleService">
<ref bean="tnEntrInfoMScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--1.2 관세청 통관정보 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="tnEntrInfoMCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="tnEntrInfoCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat1.cron.expression}"/>
</bean>
<!-- 2.1 코드마스터,코드상세 Cron Quartz Scheduler -->
<bean id="ncomCdMstrInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NcomCdMstrInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="ncomCdMstrInterfaceScheduleService">
<ref bean="ncomCdMstrInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--2.2 코드마스터,코드상세 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="ncomCdMstrInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ncomCdMstrInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat2.cron.expression}"/>
</bean>
<!-- 3.1 업체마스터 Cron Quartz Scheduler -->
<bean id="ncomCoMstrInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NcomCoMstrInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="ncomCoMstrInterfaceScheduleService">
<ref bean="ncomCoMstrInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--3.2 업체마스터 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="ncomCoMstrInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ncomCoMstrInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat3.cron.expression}"/>
</bean>
<!-- 4.1 기관법정동 Cron Quartz Scheduler -->
<bean id="ncomGovInsttBizAreaMapInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NcomGovInsttBizAreaMapInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="ncomGovInsttBizAreaMapInterfaceScheduleService">
<ref bean="ncomGovInsttBizAreaMapInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--4.2 기관법정동 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="ncomGovInsttBizAreaMapInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ncomGovInsttBizAreaMapInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat4.cron.expression}"/>
</bean>
<!-- 5.1 정부기관마스터 Cron Quartz Scheduler -->
<bean id="ncomGovInsttMstrInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NcomGovInsttMstrInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="ncomGovInsttMstrInterfaceScheduleService">
<ref bean="ncomGovInsttMstrInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--5.2 정부기관마스터 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="ncomGovInsttMstrInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ncomGovInsttMstrInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat5.cron.expression}"/>
</bean>
<!-- 6.1 ID마스터 Cron Quartz Scheduler -->
<bean id="ncomIdMstrInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NcomIdMstrInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="ncomIdMstrInterfaceScheduleService">
<ref bean="ncomIdMstrInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--6.2 ID마스터 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="ncomIdMstrInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ncomIdMstrInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat6.cron.expression}"/>
</bean>
<!-- 7.1 품목마스터 Cron Quartz Scheduler -->
<bean id="ncomItemMstrInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NcomItemMstrInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="ncomItemMstrInterfaceScheduleService">
<ref bean="ncomItemMstrInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--7.2 품목마스터 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="ncomItemMstrInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ncomItemMstrInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat7.cron.expression}"/>
</bean>
<!-- 8.1 법정동 Cron Quartz Scheduler -->
<bean id="ncomLawdInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NcomLawdInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="ncomLawdInterfaceScheduleService">
<ref bean="ncomLawdInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--8.2 법정동 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="ncomLawdInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ncomLawdInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat8.cron.expression}"/>
</bean>
<!-- 9.1 휴일 Cron Quartz Scheduler -->
<bean id="nuciHldyInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.NuciHldyInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="nuciHldyInterfaceScheduleService">
<ref bean="nuciHldyInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--9.2 휴일 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="nuciHldyInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="nuciHldyInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat9.cron.expression}"/>
</bean>
<!-- 10.1 사용자기관업체관계 Cron Quartz Scheduler -->
<bean id="tnUserInsttEntrpsRInterfaceCronQuartzJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="egovframework.tibero.schedule.inter.service.TnUserInsttEntrpsRInterfaceJobScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="tnUserInsttEntrpsRInterfaceScheduleService">
<ref bean="tnUserInsttEntrpsRInterfaceScheduleService"/>
</entry>
</map>
</property>
</bean>
<!--10.2 사용자기관업체관계 5분마다 Scheduler Trigger cronExpression setting -->
<bean id="tnUserInsttEntrpsRInterfaceCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="tnUserInsttEntrpsRInterfaceCronQuartzJob"/>
<property name="cronExpression" value="${scheduler.tibero.stat10.cron.expression}"/>
</bean>
<!-- Scheduler Trigger -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="tnEntrInfoMCronTrigger"/>
<ref bean="ncomCdMstrInterfaceCronTrigger"/>
<ref bean="ncomCoMstrInterfaceCronTrigger"/>
<ref bean="ncomGovInsttBizAreaMapInterfaceCronTrigger"/>
<ref bean="ncomGovInsttMstrInterfaceCronTrigger"/>
<ref bean="ncomIdMstrInterfaceCronTrigger"/>
<ref bean="ncomItemMstrInterfaceCronTrigger"/>
<ref bean="ncomLawdInterfaceCronTrigger"/>
<ref bean="nuciHldyInterfaceCronTrigger"/>
<ref bean="tnUserInsttEntrpsRInterfaceCronTrigger"/>
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">5</prop>
<prop key="org.quartz.threadPool.threadPriority">4</prop>
<prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
</props>
</property>
</bean>
</beans>
- globals.properties
# 스케줄러 매일 매시 5분 주기 실행
#scheduler.tibero.stat.cron.expression = 0 */5 * * * ?
# 1. 관세청 통관정보 스케줄러 매일 매시 1시간 주기 실행
scheduler.tibero.stat1.cron.expression = 0 0 */1 * * ?
# 2. 코드마스터,코드상세 스케줄러 매일 매시 1시간 주기 실행
scheduler.tibero.stat2.cron.expression = 0 0 */1 * * ?
# 3. 업체마스터 스케줄러 매일 매시 10분 주기 실행
scheduler.tibero.stat3.cron.expression = 0 */10 * * * ?
# 4. 기관법정동 스케줄러 매일 매시 30분 주기 실행
scheduler.tibero.stat4.cron.expression = 0 */30 * * * ?
# 5. 정부기관마스터 스케줄러 매일 매시 3시간 주기 실행
scheduler.tibero.stat5.cron.expression = 0 0 */3 * * ?
# 6. ID마스터 스케줄러 매일 매시 6분 주기 실행
scheduler.tibero.stat6.cron.expression = 0 */6 * * * ?
# 7. 품목마스터 스케줄러 매일 매시 5시간 주기 실행
scheduler.tibero.stat7.cron.expression = 0 0 */5 * * ?
# 8. 법정동 스케줄러 매일 매시 50분 주기 실행
scheduler.tibero.stat8.cron.expression = 0 */50 * * * ?
# 9. 휴일 스케줄러 매일 매시 12시간 주기 실행
scheduler.tibero.stat9.cron.expression = 0 0 */12 * * ?
# 10. 사용자기관업체관계 스케줄러 매일 매시 5분 주기 실행
scheduler.tibero.stat10.cron.expression = 0 */5 * * * ?
3개의 자바 클래스를 생성한다.
1. QuartzJobBean을 상속받은 jobScheduler 클래스를 생성한다.
TnEntrInfoJobScheduler.java
package egovframework.tibero.schedule.inter.service;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.net.InetAddress;
@Slf4j
public class TnEntrInfoJobScheduler extends QuartzJobBean {
@Autowired
private TnEntrInfoMScheduleService tnEntrInfoMScheduleService;
public TnEntrInfoMScheduleService getTnEntrInfoMScheduleService()
{
return this.tnEntrInfoMScheduleService;
}
public void setTnEntrInfoMScheduleService(TnEntrInfoMScheduleService tnEntrInfoMScheduleService)
{
this.tnEntrInfoMScheduleService = tnEntrInfoMScheduleService;
}
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
try
{
InetAddress iadr = InetAddress.getLocalHost();
String hostName = iadr.getHostName();
//스케줄러는 내부와스1번에서만 기동 중복기동방지
if(hostName.equals("Pass_inWAS01")) {
log.debug("관세청 통관정보 Job Scheduler Start : " + this.tnEntrInfoMScheduleService);
this.tnEntrInfoMScheduleService.executeTnEntrInfoM();
log.info("관세청 통관정보 Job Scheduler Job End!");
}
} catch (Exception e) {
log.error("관세청 통관정보 스케줄 실행 오류");
}
}
}
2. 서비스 인터페이스 생성
TnEntrInofMScheduleService.java
package egovframework.tibero.schedule.inter.service;
public abstract interface TnEntrInfoMScheduleService {
public abstract void executeTnEntrInfoM() throws Exception;
}
3. 서비스 인터페이스를 상속받은 서비스 클래스 생성
TnEntrInfoMScheduleServiceImpl.java
package egovframework.tibero.schedule.inter.service;
import egovframework.frmprd.link.service.TiberoToPostgresService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Slf4j
@Service("tnEntrInfoMScheduleService")
@DisallowConcurrentExecution
public class TnEntrInfoMScheduleServiceImpl implements TnEntrInfoMScheduleService{
@Resource(name = "tiberoToPostgresService")
private TiberoToPostgresService tiberoToPostgresService;
@Override
public void executeTnEntrInfoM() throws Exception {
log.debug("관세청 통관정보 Start");
tiberoToPostgresService.executeTnEntrInfoM();
log.debug("관세청 통관정보 End");
}
}
728x90
반응형
'프로그램 > 자바' 카테고리의 다른 글
자바 cors 우회하기 get,post방식 (0) | 2022.07.12 |
---|---|
자바 랜덤 API 암호화 BASE64 KEY 생성 (0) | 2022.01.13 |
자바로 크로스 도메인 우회처리 (0) | 2021.12.14 |
open api 국세청 사업자정보 진위확인 (0) | 2021.12.14 |
자바로 PWA PUSH 만들기 (0) | 2021.08.06 |
댓글