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

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

相关文章
|
5月前
|
监控 Java BI
《深入理解Spring》定时任务——自动化调度的时间管理者
Spring定时任务通过@Scheduled注解和Cron表达式实现灵活调度,支持固定频率、延迟执行及动态配置,结合线程池与异常处理可提升可靠性,适用于报表生成、健康检查等场景,助力企业级应用自动化。
|
6月前
|
缓存 Java 应用服务中间件
Spring Boot配置优化:Tomcat+数据库+缓存+日志,全场景教程
本文详解Spring Boot十大核心配置优化技巧,涵盖Tomcat连接池、数据库连接池、Jackson时区、日志管理、缓存策略、异步线程池等关键配置,结合代码示例与通俗解释,助你轻松掌握高并发场景下的性能调优方法,适用于实际项目落地。
1057 5
|
6月前
|
jenkins Java 持续交付
使用 Jenkins 和 Spring Cloud 自动化微服务部署
随着单体应用逐渐被微服务架构取代,企业对快速发布、可扩展性和高可用性的需求日益增长。Jenkins 作为领先的持续集成与部署工具,结合 Spring Cloud 提供的云原生解决方案,能够有效简化微服务的开发、测试与部署流程。本文介绍了如何通过 Jenkins 实现微服务的自动化构建与部署,并结合 Spring Cloud 的配置管理、服务发现等功能,打造高效、稳定的微服务交付流程。
726 0
使用 Jenkins 和 Spring Cloud 自动化微服务部署
|
8月前
|
Java 关系型数据库 数据库连接
Spring Boot项目集成MyBatis Plus操作PostgreSQL全解析
集成 Spring Boot、PostgreSQL 和 MyBatis Plus 的步骤与 MyBatis 类似,只不过在 MyBatis Plus 中提供了更多的便利功能,如自动生成 SQL、分页查询、Wrapper 查询等。
776 3
|
7月前
|
Java jenkins 应用服务中间件
结合Jenkins与Tomcat,实施Maven项目的自动构建和部署流程。
任何项目构建和部署的自动化流程,总离不开对各个环节精细把控与密切配合。涉及到源代码管理、构建工具、持续集成服务器以及最终的运行时环境的协调。通过上述简洁实用的步骤,可以实现Maven项目从源代码到运行状态的无缝过渡,进而提升软件开发的效率与质量。
380 0
|
8月前
|
前端开发 Java API
酒店管理系统基于 JavaFX Spring Boot 和 React 经典项目重构实操
本文介绍了基于现代技术栈的酒店管理系统开发方案,整合了JavaFX、Spring Boot和React三大技术框架。系统采用前后端分离架构,JavaFX构建桌面客户端,React开发Web管理界面,Spring Boot提供RESTful API后端服务。核心功能模块包括客房管理和客户预订流程,文中提供了JavaFX实现的客房管理界面代码示例和React开发的预订组件代码,展示了如何实现客房信息展示、添加修改操作以及在线预订功能。
508 0
|
8月前
|
Java 测试技术 Spring
简单学Spring Boot | 博客项目的测试
本内容介绍了基于Spring Boot的博客项目测试实践,重点在于通过测试驱动开发(TDD)优化服务层代码,提升代码质量和功能可靠性。案例详细展示了如何为PostService类编写测试用例、运行测试并根据反馈优化功能代码,包括两次优化过程。通过TDD流程,确保每项功能经过严格验证,增强代码可维护性与系统稳定性。
323 0
|
8月前
|
存储 Java 数据库连接
简单学Spring Boot | 博客项目的三层架构重构
本案例通过采用三层架构(数据访问层、业务逻辑层、表现层)重构项目,解决了集中式开发导致的代码臃肿问题。各层职责清晰,结合依赖注入实现解耦,提升了系统的可维护性、可测试性和可扩展性,为后续接入真实数据库奠定基础。
613 0
|
8月前
|
Java 应用服务中间件 Maven
第01课:Spring Boot开发环境搭建和项目启动
第01课:Spring Boot开发环境搭建和项目启动
1769 0

热门文章

最新文章