日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java spring 集成定时器

發布時間:2025/5/22 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java spring 集成定时器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

接口

public interface Time {
?? ?public void execute() ;
}
實現類

@Component(value = "logTask")//xml中裝配
public class TimeUtil implements Time{

?? ?@Override
?? ?public void execute() {
?? ??? ?// TODO Auto-generated method stub

? ? ? ?要實現的方法
?? ??? ?System.out.println("啟動了");
?? ?}

}
spring-job.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"
?? ?xsi:schemaLocation=" ?
? ? ? ? http://www.springframework.org/schema/beans ??
? ? ? ? http://www.springframework.org/schema/beans/spring-beans.xsd">

?? ?<bean id="jobDetail"
?? ??? ?class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
?? ??? ?<property name="targetObject">
?? ??? ??? ?<ref bean="logTask" />//裝備的類
?? ??? ?</property>
?? ??? ?<property name="targetMethod">
?? ??? ??? ?<value>execute</value>//執行的方法
?? ??? ?</property>
?? ?</bean>

?? ?<bean id="jobTrigger"
?? ??? ?class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
?? ??? ?<property name="jobDetail">
?? ??? ??? ?<ref bean="jobDetail" />
?? ??? ?</property>
?? ??? ?<property name="cronExpression">
?? ??? ??? ?<value>0 21 19 * * ?</value>//時間
?? ??? ?</property>
<!-- ?? ?
?? ??? ?字段?? ? ?? ?允許值?? ? ?? ?允許的特殊字符
秒?? ? ?? ?0-59?? ? ?? ?, - * /
分?? ? ?? ?0-59?? ? ?? ?, - * /
小時?? ? ?? ?0-23?? ? ?? ?, - * /
日期?? ? ?? ?1-31?? ? ?? ?, - * ? / L W C
月份?? ? ?? ?1-12 或者 JAN-DEC?? ? ?? ?, - * /
星期?? ? ?? ?1-7 或者 SUN-SAT?? ? ?? ?, - * ? / L C #
年(可選)?? ? ?? ?留空, 1970-2099?? ? ?? ?, - * /
?-->?? ?
?? ?</bean>

?? ?<bean id="jobScheduler"
?? ??? ?class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
?? ??? ?<property name="triggers">
?? ??? ??? ?<list>
?? ??? ??? ??? ?<ref bean="jobTrigger" />
?? ??? ??? ?</list>
?? ??? ?</property>
?? ?</bean>

</beans>

?

最后在spring-context.xml中進行注冊:

<import resource="classpath:spring/spring-job.xml" />?

轉載于:https://my.oschina.net/xiaoshoubingliang/blog/729716

總結

以上是生活随笔為你收集整理的java spring 集成定时器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。