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

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

相关文章
|
21天前
|
移动开发 Java 应用服务中间件
tomcat第1章 tomcat介绍、安装、部署项目
tomcat第1章 tomcat介绍、安装、部署项目
|
4天前
|
Java Maven Docker
0.07 秒启动一个 SpringBoot 项目!Spring Native 很强!!
0.07 秒启动一个 SpringBoot 项目!Spring Native 很强!!
17 2
|
5天前
|
canal 缓存 关系型数据库
Spring Boot整合canal实现数据一致性解决方案解析-部署+实战
Spring Boot整合canal实现数据一致性解决方案解析-部署+实战
|
7天前
|
Dubbo Java 应用服务中间件
启动tomcat时,卡主在信息: Initializing Spring FrameworkServlet 'e3-manager'
启动tomcat时,卡主在信息: Initializing Spring FrameworkServlet 'e3-manager'
8 0
|
11天前
|
Java Linux 虚拟化
Docker 部署spring-boot项目(超详细 包括Docker详解、Docker常用指令整理等)
Docker 部署spring-boot项目(超详细 包括Docker详解、Docker常用指令整理等)
53 1
|
12天前
|
Java 应用服务中间件 Linux
在阿里云服务器上部署Tomcat详细图文详解
本文介绍了在阿里云服务器上安装和配置JDK和Tomcat的步骤。首先,需要注册阿里云账号并进行实名认证,然后购买并设置服务器。接着,通过File Zilla连接服务器,创建Java和Tomcat的安装目录,并将JDK和Tomcat的tar.gz文件上传到服务器,解压并重命名。之后,配置JDK的环境变量,将catalina.sh复制到/etc/init.d/目录下,并修改相关配置。最后,启动Tomcat并配置安全组规则,确保可以通过公网访问。
|
15天前
|
Web App开发 Java 应用服务中间件
【Java Web】在 IDEA 中部署 Tomcat
【Java Web】在 IDEA 中部署 Tomcat
|
16天前
|
缓存 Java Spring
单体项目中资源管理模块集成Spring Cache
该内容是关于将Spring Cache集成到资源管理模块以实现缓存同步的说明。主要策略包括:查询时添加到缓存,增删改时删除相关缓存。示例代码展示了@Service类中使用@Transactional和@Cacheable注解进行缓存操作,以及在RedisTemplate中处理缓存的示例。
24 5
|
18天前
|
Java 应用服务中间件 Linux
阿里云服务器部署多个tomcat
阿里云服务器部署多个tomcat
|
18天前
|
JSON 前端开发 Java
统一异常处理:让Spring Boot项目异常更优雅
统一异常处理:让Spring Boot项目异常更优雅
26 1