Jeesite中部署定时任务,定时任务tomcat部署详细,定时任务在spring项目中部署

本文介绍如何在Spring框架中配置和使用定时任务,通过XML配置及注解实现任务调度,并展示具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面给大家详细的介绍下 定时任务的部署:

第一种方式

一. spring-context.xml配置加入

xmlns:task=”http://www.springframework.org/schema/task”
xsi:schemaLocation下面:http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd

在这里插入图片描述

二. 继续spring-context.xml配置加入

<!– 计划任务配置,用 @Service @Lazy(false)标注类,用@Scheduled(cron = “0 0 2 * * ?”)标注方法 –>
<task:executor id=”executor” pool-size=”10″/> <task:scheduler id=”scheduler” pool-size=”10″/>
<task:annotation-driven scheduler=”scheduler” executor=”executor” proxy-target-class=”true”/>

代码基于注解形式的task

package com.thinkgem.jeesite.modules.sys.service;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
* Created by Administrator on 2016/6/22.
*/
@Service
@Lazy(false)
public class TaskJob2 {
@Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次
public void job1() {
System.out.println("spring task 注解使用。。。任务进行中");
}
}

发布项目即可在输出行里看到输出结果

**


   @Async // 异步
    //@Scheduled(cron = "0 15 5 * * ?")  //每天早上5:15触发
    //@Scheduled(cron = "0/5 * * * * ? ")
    public void testSpringTimer() {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("开始执行 => " + simpleDateFormat.format(new Date()));}
package com.thinkgem.jeesite.modules.yanlink.duizhang.task;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 闫文超宝宝
 */ //http://blog.lunhui.ren/archives/280
//<!– 计划任务配置,用 @Service @Lazy(false)标注类,用@Scheduled(cron = “0 0 2 * * ?”)标注方法 –>
//<task:executor id=”executor” pool-size=”10″/> <task:scheduler id=”scheduler” pool-size=”10″/>
//<task:annotation-driven scheduler=”scheduler” executor=”executor” proxy-target-class=”true”/>
@EnableScheduling()/*控制定时器是否生效*/
@Service
@Lazy(false)
@Controller

public class taksJob {

    @Scheduled(cron = "0/5 * * * * ? ")   //每5秒执行一次
    public void job1() {
        System.out.println("spring task 注解使用。。。任务进行中");
    }
    @Scheduled(cron = "0/5 * * * * ? ")
    public void testSpringTimer(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("开始执行 => " + simpleDateFormat.format(new Date()));
    }


    public static void main(String[] args) {
        taksJob taksJob = new taksJob();
            taksJob.testSpringTimer();
            taksJob.job1();
        return;
    }

}

这个启动tomcat才可启动 因为注解
在这里插入图片描述

上面这些都是比较常见的我记录下自己操作
我的配置路径在配置文件 想用定时任务 获取操作

html

@Value("${logPath.Log.address}")
private String htmlu;

@RequestMapping("/ts")
@ResponseBody
public String test(){
    return htmlu;
}

  @Async // 异步
    //@Scheduled(cron = "0 15 5 * * ?")  //每天早上5:15触发
    @Scheduled(cron = "0/5 * * * * ? ")
    public void testSpringTimer() {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("开始执行 => " + simpleDateFormat.format(new Date()));
//
        try {
          System.out.println("配置文件路径:---" + htmlu);
            ImportExcel ei = new ImportExcel(htmlu, 0, 0);

在这里插入图片描述


	<!-- 加载配置属性文件 -->
	<context:property-placeholder
		ignore-unresolvable="true" location="classpath:jeesite.properties" />
	<!-- 使用Annotation自动注册Bean,只扫描@Controller -->
	<context:component-scan base-package="com.thinkgem.jeesite"
		use-default-filters="false"><!-- base-package 如果多个,用“,”分隔 -->
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

在这里插入图片描述

logPath.Log.address=C:\\Users\\75763\\Desktop\\商户对账单\\shanghuduizhang.xls

这样基本就可以了 只是粗糙记录下 防止自己忘掉 后期会优化博客,如您有此方面有需求 希望可以帮助您 可以联系我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

默语佬

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值