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

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

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


第一种方式


一. spring-context.xml配置加入


xmlns:task=”http://www.springframework.org/schema/task

xsi:schemaLocation下面:http://www.springframework.org/schema/taskhttp://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

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

相关文章
|
3天前
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
25 7
|
1月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
58 23
|
1月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
49 22
|
1月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
64 25
|
2月前
|
存储 JSON 前端开发
【Spring项目】表白墙,留言板项目的实现
本文主要介绍了表白墙项目的实现,包含前端和后端代码,以及测试
|
2月前
|
JSON 前端开发 Java
|
2月前
|
缓存 前端开发 Java
【Spring】——SpringBoot项目创建
SpringBoot项目创建,SpringBootApplication启动类,target文件,web服务器,tomcat,访问服务器
|
Java 应用服务中间件 Spring
|
4月前
|
安全 应用服务中间件 网络安全
Tomcat如何配置PFX证书?
【10月更文挑战第2天】Tomcat如何配置PFX证书?
336 7
|
4月前
|
存储 算法 应用服务中间件
Tomcat如何配置JKS证书?
【10月更文挑战第2天】Tomcat如何配置JKS证书?
551 4