定时任务quartz
阅读原文时间:2023年07月11日阅读:2

pom引入

org.quartz-scheduler

quartz

1.8.6

配置文件xml中引入

schedule-center.xml内容:

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"

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

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/tx

http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/jee

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

default-lazy-init="false">

<bean id="schedulerFactory" lazy-init="false" autowire="no"

class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

envPropertyLoader.xml

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">

classpath:/properties/tp-schedule.properties

schedule-syncTeamName-config.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"

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

http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/jee

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

default-lazy-init="false">

${tp-schedule.SYNCTEAMNAMEJOB}

execute

syncTeamNameJobExecutor

public class syncTeamNameJobExecutor {

private Logger logger = Logger.getLogger(this.getClass());

private IBdf2DeptService iBdf2DeptServiceImpl;

public void execute(){

logger.info("**-----开始同步TeamName");

iBdf2DeptServiceImpl.insertbdf2dept();

logger.info("**-----同步TeamName完成");

}

public void setiBdf2DeptServiceImpl(IBdf2DeptService iBdf2DeptServiceImpl) {

this.iBdf2DeptServiceImpl = iBdf2DeptServiceImpl;

}

}