spring定时器
程序员文章站
2022-06-12 21:12:13
...
<?xml version="1.0" encoding="UTF-8"?> <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.0.xsd"> <bean id="rebateJob" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass"> <value>com.rebate.scheduled.job.RebateQuartz</value> </property> </bean> <!-- 复杂触发器 --> <bean id="rebateCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="rebateJob" /> </property> <property name="cronExpression"> <!-- 配置时间 6至9时每5分钟执行一次--> <value>0 0/5 6-9 * * ?</value> <!--测试用的--> <!--<value>0/3 * * * * ?</value>--> </property> </bean> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <ref bean="rebateCronTrigger" /> </property> <property name="autoStartup"> <value>false</value> </property> </bean> </beans>
定时运行的东西
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.scheduling.quartz.QuartzJobBean; public class RebateQuartz extends QuartzJobBean { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {} }
启动
import org.quartz.impl.StdScheduler; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class AutoRebate { public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath*:/spring/*.xml"); StdScheduler scheduler = (StdScheduler) context.getBean("scheduler"); scheduler.start(); } }
上一篇: PowerMock应用
下一篇: 揭露摆地摊商品真相
推荐阅读
-
SpringBoot 源码解析 (三)----- Spring Boot 精髓:启动时初始化数据
-
Spring-Cloud-Filter(过滤器)
-
spring依赖注入
-
bootstrap+spring mvc+ibatis 实现增删改查
-
gRPC在Spring Cloud中的应用
-
Spring 的 ApplicationEvent and ApplicationListener
-
Spring @Async异步执行方法
-
web.xml 配置 contextConfigLocation(多个Spring配置文件)
-
idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理
-
Spring从MongoDB中下载文件之GridFS