当前位置: 首页 > news >正文

做网站一般做几个尺寸一个品牌的策划方案

做网站一般做几个尺寸,一个品牌的策划方案,马鞍山网站建设,加网络网站建设工作室​ 博客主页: 南来_北往 系列专栏:Spring Boot实战 前言 最近一周,被借调到其他部门,赶一个紧急需求,需求内容如下: PC网页触发一条设备升级记录(下图),后台要定时批量设备更…

 ​

 博客主页:     南来_北往

系列专栏:Spring Boot实战


前言

最近一周,被借调到其他部门,赶一个紧急需求,需求内容如下:

PC网页触发一条设备升级记录(下图),后台要定时批量设备更新。这里定时要用到Quartz,批量数据处理要用到SpringBatch,二者结合,可以完成该需求。

由于之前,没有用过SpringBatch,于是上网查了下资料,发现可参考的不是很多,于是只能去慢慢的翻看官方文档。

Spring Batch - Reference Documentation

具体实现

在你的pom.xml文件中添加以下依赖: 

<dependencies><!-- Spring Boot --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-batch</artifactId></dependency><!-- Quartz --><dependency><groupId>org.quartz-scheduler</groupId><artifactId>quartz</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId></dependency>
</dependencies>

 在application.properties文件中添加以下配置:

spring.quartz.job-store-type=memory
spring.quartz.properties.org.quartz.scheduler.instanceName=MyScheduler
spring.quartz.properties.org.quartz.threadPool.threadCount=5

 创建一个实现Job接口的类,例如MyBatchJob

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;public class MyBatchJob extends QuartzJobBean {@Autowiredprivate JobLauncher jobLauncher;@Overrideprotected void executeInternal(JobExecutionContext context) throws JobExecutionException {try {jobLauncher.run(myBatchJob(), new JobParametersBuilder().addString("JobID", String.valueOf(System.currentTimeMillis())).toJobParameters());} catch (Exception e) {throw new JobExecutionException(e);}}private Job myBatchJob() {// 返回你的Spring Batch Job实例}
}

 在你的配置类中(例如ApplicationConfig),添加一个SchedulerFactoryBean的Bean,用于配置定时任务的触发器:

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;@Configuration
public class ApplicationConfig {@Beanpublic JobDetail myBatchJobDetail() {return JobBuilder.newJob(MyBatchJob.class).withIdentity("myBatchJob").storeDurably().build();}@Beanpublic Trigger myBatchJobTrigger() {SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(60) // 设置任务执行间隔,例如每60秒执行一次.repeatForever(); // 设置任务重复执行return TriggerBuilder.newTrigger().forJob(myBatchJobDetail()).withIdentity("myBatchJobTrigger").withSchedule(scheduleBuilder).build();}@Beanpublic SchedulerFactoryBean schedulerFactoryBean() {SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();schedulerFactoryBean.setJobDetails(myBatchJobDetail());schedulerFactoryBean.setTriggers(myBatchJobTrigger());return schedulerFactoryBean;}
}

现在,你已经成功地整合了Spring Boot、Spring Batch和Quartz,实现了定时批量任务。每隔指定的时间间隔(例如60秒),MyBatchJob将会被执行一次。

http://www.hkea.cn/news/742496/

相关文章:

  • 政府网站 建设 计划品牌推广策划方案案例
  • 临沂网站建设那家好小米市场营销案例分析
  • 德化网站建设企业中层管理人员培训课程
  • 网站怎么通过流量赚钱爱站网能不能挖掘关键词
  • 网站建设课后感营销型网站有哪些平台
  • 哪个网站做生鲜配送厦门seo外包公司
  • 水电行业公司设计logo重庆seo排名扣费
  • 可信赖的南昌网站制作站长工具网站
  • 济南建站公司电话成都关键词自然排名
  • 门户网站开发公司推广网页
  • 如何做网站认证实时军事热点
  • 上海的网站建设公司哪家好企业网站建设
  • 专业b2c电商网站制作网站推广要点
  • 现在的网站用什么程序做百度云官网登录入口
  • vs做网站怎样加数据库新闻小学生摘抄
  • 广州做网站mxszpt小说排行榜
  • 有什么网站是python做的网站营销策划公司
  • 长春有什么好的网站制作公司链接购买
  • 毕设网站佛山网站建设十年乐云seo
  • 北京做网站建设的公司哪家好手机怎么创建网站
  • winforms做网站注册百度账号
  • 玉泉路网站建设营销培训课程有哪些
  • 渭南做网站费用搜索引擎排名优化是什么意思
  • 做网站开发需要学什么软件微信公众平台开发
  • 网站整体营销方案网络营销的特点是什么?
  • 国内知名的网站建设公司有哪些百度指数专业版app
  • 画画外包网站如何推广一个网站
  • 互联网公司响应式网站深圳google推广
  • 深圳网站设计哪好什么推广平台比较好
  • 打开英文网站字体不对教程seo推广排名网站