Tag: spring batch

如何触发预定的Spring批处理作业?

我希望能够使用REST控制器开始我的工作,然后当作业启动时,它应该按计划运行,直到我再次使用REST停止它。 所以这是我的控制器: @RestController public class LauncherController { @Autowired JobLauncher jobLauncher; @Autowired Job job; @RequestMapping(“/launch”) public String launch() throws Exception { … jobLauncher.run(job, jobParameters); } 这是Batch conf的一部分: @Configuration @EnableBatchProcessing @EnableScheduling public class BatchConfiguration { @Autowired public JobBuilderFactory jobBuilderFactory; @Autowired public StepBuilderFactory stepBuilderFactory; @Scheduled(cron = “0/5 * * * * ?”) @Bean public Job job() { return […]

spring amqp rabbitmq MessageListener无效

我想使用spring amqp使用rabbitmq,下面是我的配置。 这是一个简单的Message Listener类, import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageListener; public class ImportMessageListener implements MessageListener { @Override public void onMessage(Message message) { System.out.println(“consumer output: ” + message); } } 这是生产者(spring批次的itemWriter), public class ImportItemWriter implements ItemWriter { private AmqpTemplate template; public AmqpTemplate getTemplate() { return template; } public void setTemplate(AmqpTemplate template) { this.template = template; } public void […]

Spring Batch @StepScope无法生成CGLIB子类

编辑 我创建了一个复制问题的测试项目。 它可以在https://github.com/tomverelst/test-batch找到。 首先运行maven命令exec:java来启动HSQL数据库。 然后,您可以运行JUnit测试MigrationJobConfigurationTest来加载Spring应用程序上下文。 原始问题 启动Spring Batch应用程序时,Spring加载我的作业配置时出现以下exception: Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy34]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy34 这是由我的作业配置中的@StepScope注释引起的。 它试图用已经用JDK代理代理的CGLIB代理一个类,我不知道这个JDK代理的来源。 我也尝试过使用@Scope(value = “step”, proxyMode = ScopedProxyMode.NO) ,但是在调用JDK代理时会出现堆栈溢出错误,而JDK代理一直在调用自己。 如果删除@StepScope注释,应用程序将正确启动,但我需要能够将它们用于我的工作。 Spring配置 […]

Spring Batch:如何监控当前正在运行的作业并在jsp页面上显示进度

我想知道如何监视当前正在运行的批处理作业的状态。我的作业基本上处理文件夹有一些默认步骤,所以我想逐步向用户显示进度。我正在使用Tasklets和DB Job Repository。解释一些实现这一目标的示例代码将更有帮助。 谢谢。

如何使用spring Batch注释将Job参数传递到项目处理器

我正在使用spring MVC。 从我的控制器,我正在调用jobLauncher和jobLauncher我传递的作业参数如下,我正在使用注释来启用配置如下: @Configuration @EnableBatchProcessing public class BatchConfiguration { // read, write ,process and invoke job } JobParameters jobParameters = new JobParametersBuilder().addString(“fileName”, “xxxx.txt”).toJobParameters(); stasrtjob = jobLauncher.run(job, jobParameters); and here is my itemprocessor public class DataItemProcessor implements ItemProcessor { public OutPutData process(final InputData inputData) throws Exception { // i want to get job Parameters here ???? […]

在jobExeuctionDecider之后执行Spring Batch(java-config)步骤

我正在尝试使用java-config在spring批处理中配置Flow,这个流程基本上必须这样做: 执行init步骤(在数据库中添加记录), 然后执行一个决策程序来检查文件是否存在, 2.1。 如果文件存在,它将执行加载作业(这是一个并行的一堆步骤的另一个流程) 执行完成步骤(在数据库中添加记录),即使2.1未执行,也应该始终运行。 我尝试进行此配置,但完成步骤永远不会运行: Flow flow = new FlowBuilder(“commonFlow”) .start(stepBuilderFactory.get(“initStep”).tasklet(initTasklet).build()) .next(decider) .on(FlowExecutionStatus.COMPLETED.getName()) .to(splitFlow) .from(decider).on(“*”) .end() .next(stepBuilderFactory.get(“finishStep”).tasklet(finishTasklet).build()) .end(); 我能够按照下面的方式工作,但它根本不优雅: Step finishStep = stepBuilderFactory.get(“finishStep”).tasklet(finishTasklet).build(); Flow flow = new FlowBuilder(“commonFlow”) .start(stepBuilderFactory.get(“initStep”).tasklet(initTasklet).build()) .next(decider) .on(FlowExecutionStatus.COMPLETED.getName()) .to(splitFlow) .next(finishStep) .from(decider).on(“*”) .to(finishStep) .end(); 有人知道在使用java-config做出决定后执行步骤的正确方法是什么?

Spring Batch:org.springframework.batch.item.ReaderNotOpenException:Reader必须先打开才能读取

我阅读了相关问题,但解决方案对我不起作用。 我得到了org.springframework.batch.item.ReaderNotOpenException: Reader must be open before it can be readexception。 以下是我的配置: @Bean @StepScope public ItemReader reader(@Value(“#{jobParameters[inputZipfile]}”) String inputZipfile) { final String [] header = { .. this part omitted for brevity … }; FlatFileItemReader reader = new FlatFileItemReader(); System.out.println(“\t\t\t\t\t”+inputZipfile); reader.setResource(new ClassPathResource(inputZipfile)); reader.setLineMapper(new DefaultLineMapper() {{ setLineTokenizer(new DelimitedLineTokenizer() {{ setNames( header ); }}); setFieldSetMapper(new BeanWrapperFieldSetMapper() {{ […]

Spring批量corePoolSize VS节流限制

我想知道corePoolSize和throttle-limit之间的区别,因为Spring Batch属性定义了multithreading配置。 由于这篇文章“Spring ThreadPoolTask​​Executor中corePoolSize和maxPoolSize有什么区别”,我对corePoolSize和maxPoolSize有所区别。 但我的问题涉及corePoolSize vs throttle-limit …我发现定义CorePoolSize = Throttle-limit更好,但我想知道……如果我定义例如:CorePoolSize = 100和Throttle-limit = 200 .. 。 怎么了 ? 是一个200大小的线程池,将创建或100? 谢谢你的任何澄清……

使用2个不同的数据源:Spring批处理

我有2个不同的数据源 ,一个用于读取,另一个用于写入如下结果: ItemReader应该从dataSource_1获取数据。 ItemWriter应该将数据写入dataSource_2。 知道读者和作者在同一个tasklet中。 根据文档,我们可以在tasklet上配置单个事务管理器 在这种情况下,我如何在这里使用事务管理器? 我不能依赖容器,我不使用ORM层(JPA ..),我使用直接JDBC驱动程序读入数据库1并写入database2。 当前conf: 我如何使用Spring Batch配置JTA / XA事务(Atomikos)?

使用Hibernate和Spring批量插入

我的应用程序基于Hibernate 3.2和Spring 2.5。 以下是应用程序上下文中与事务管理相关的代码段: 对于所有DAO,都有相关的Service类,并且在服务层中的每个方法上使用@Transactional处理事务。 但是现在有一种情况,即DAO中的方法说服务层调用“parse()”。 在服务层我指定了@Transactional(readOnly=false) 。 DAO中的这个解析方法在同一个DAO中调用另一个方法“save()”,它在数据库中存储了大量的行(大约5000个)。 现在,在解析函数的循环中调用save方法。 现在的问题是,在大约100次调用“保存”方法之后..我有时会得到OutOfMemoryexception或有时程序停止响应。 现在这些是我对save方法所做的更改: Session session = getHibernateTemplate().getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); int counter = 0; if(books!=null && !books.isEmpty()){ for (Iterator iterator = books.iterator(); iterator .hasNext();) { Book book = (Book) iterator.next(); session.save(book); counter++; if(counter % 20==0) { session.flush(); session.clear(); } } } tx.commit(); session.close(); 这是我的应用程序中唯一的方法,我开始这样的事务并在方法结束时提交它。 否则我通常只调用getHibernateTemplate.save() […]