Tag: spring batch

使用Spring Batch进行事务管理

我发现实际上是Spring,我可以设置一些工作。 现在,我想使用Hibernate / JPA将我导入的数据保存在数据库中,并且我不断收到此错误: 14:46:43.500 [main] ERROR osbcore.step.AbstractStep – Encountered an error executing the step javax.persistence.TransactionRequiredException: no transaction is in progress 我看到问题出在交易上。 这是我对entityManager和transactionManager spring java配置: @Configuration public class PersistenceSpringConfig implements EnvironmentAware { @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws Exception { // Initializes the entity manager LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); factoryBean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME); factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); factoryBean.setDataSource(dataSource()); // Scans […]

多次运行spring批处理作业

我使用以下教程创建了一个带有spring boot的spring批处理作业: https://spring.io/guides/gs/batch-processing/ 工作是读取文件并按预期写入数据库。 但是,现在我有一个用例来多次运行这个工作。 我有一个参数的ArrayList 。 我应该对作业做些什么改变,以便我可以运行我的ArrayList大小的作业次数?

如何使用springbatch从xls导入mysql数据库?

我正在尝试创建一个接收.xlsx文件作为输入的api。 文件中的数据导入mysql数据库。 已经完成了一些教程。 能够在硬编码文件路径时使其完美运行,并且一旦服务器启动,它就会成功执行。 但是当我尝试从用户和进程接收文件时,我收到错误。 此外,我没有找到相同的资源。 下面是我的代码和错误。 @Controller public class FileController1 { @Autowired private JobLauncher jobLauncher; @Autowired private Job importUserJob; @Autowired public JobBuilderFactory jobBuilderFactory; @Autowired public StepBuilderFactory stepBuilderFactory; @Autowired ExcelFileToDatabaseJobConfig excelFileToDatabaseJobConfig; @Bean ItemReader excelStudentReader(@Value(“#{jobParameters[fullPathFileName]}”) String pathToFile) throws Exception{ System.out.println(“inside excelStudentReader”); PoiItemReader reader = new PoiItemReader(); reader.setLinesToSkip(1); reader.setResource(new ClassPathResource(pathToFile)); //reader.setResource(new UrlResource(“file:///D:/joannes/ee.xlsx”)); reader.setRowMapper(excelRowMapper()); return reader; } private […]

我想创建一个批处理不使用我的数据源的spring批处理项目

我已经看到很多Spring Batch项目的例子,其中(a)定义了一个dataSource,或者(b)没有定义dataSource。 但是,在我的项目中,我希望我的业务逻辑可以访问dataSource,但我希望Spring Batch不使用dataSource。 这可能吗? 这家伙有类似的问题: Spring boot +没有DataSource的spring批处理

Spring Batch:聚合读者/作者问题

我正在尝试使用Spring批处理并实现聚合读取器(批处理文件,其中多个记录在写入时应被视为一个记录)。 以下是我的读者的代码段: public class AggregatePeekableReader implements ItemReader<List>, ItemStream { private SingleItemPeekableItemReader reader; private boolean process(T currentRecord , InvoiceLineItemsHolder holder) throws UnexpectedInputException, ParseException, Exception { next = peekNextInvoiceRecord(); // finish processing if we hit the end of file if (currentRecord == null ) { LOG.info(“Exhausted ItemReader ( END OF FILE)”); holder.exhausted = true; return false; } […]

Spring Batch – MongoDB到XML – 引起:java.lang.IllegalStateException:需要将输入转换为的类型

我正在开发Spring Batch – MongoDB to XML例子。 在这个例子中,当我运行main方法时,我看到下面的错误是cominng。 请指导以下错误。 我试图在网上找到解决方案,但我还没有在网上找到任何有用的东西。 Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘step1’: Cannot resolve reference to bean ‘mongodbItemReader’ while setting bean property ‘itemReader’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘mongodbItemReader’ defined in class path resource [job-report.xml]: Invocation of init method failed; nested exception is […]

Spring Batch – 基于字段值的多个编写器

我正在为春季批处理工作,目前正在使用FlatFileItemWriter。 我想根据一些字段值将输入文件内容写入多个平面文件。 Spring批处理默认支持任何类型的function。[类似于CompositeItemWriter] 例如,我的输入文件内容是这样的。 john,35,retail,10000 joe,34,homeloan,20000 Amy,23,retail,2000 现在我想基于第三列编写两个不同的文件,这意味着第1行和第3行应该转到file1,第2行应该转到file2。 我的编写器配置是:

使用StaxEventItemWriter构建非平凡的XML文件

我需要使用这种结构将一些数据库表的内容转储到XML文件 value value value … … 每个表的未知记录的实际数量,因此我无法将单个表的所有数据存储在内存中并转储到XML。 我现在的工作定义为: RecordBean public class RecordBeanRowMapper implements RowMapper { final static RowMapper<Map> columnMapRowMapper = new ColumnMapRowMapper(); private String tableName; public void setTableName(String tableName) { this.tableName = tableName; } @Override public RecordBean mapRow(ResultSet rs, int rowNum) throws SQLException { final RecordBean b = new RecordBean(); b.setTableName(tableName); b.setColumnValues(Maps.transformValues(columnMapRowMapper.mapRow(rs, rowNum), new Function() […]

Spring批处理:输入资源不存在类路径资源

我目前正在开发一个弹簧批处理,它在第一步将Excel(.xsls)文件转换为CVS,然后读取CVS处理它并将其数据存储在数据库中。 第一步效果很好。 批处理停止在第二步抛出此警告:输入资源不存在类路径资源[C:/work/referentielAgenceCE.csv]。 在我的代码之后: spring-config.xml: step1:convertXLSXtoCVS.java public class convertXLSXtoCVS implements Tasklet, InitializingBean{ @Value(“${batch.referentielAgenceCE.inputFilePathXLSX}”) private String inputFile; @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println(“convertXLSXtoCVS.execute1”); // For storing data into CSV files StringBuffer data = new StringBuffer(); try { File outputFile = new File(getOutputFile(inputFile)); FileWriter fw = new FileWriter(outputFile.getPath()); BufferedWriter fos = new […]

Spring Batch – TaskletStep中的可跳过exception

如果发生某种exception,我试图让一个作业没有BatchStatus.FAILED 。 文档讨论了在使用skippable-exception-classes ,但是如何在TaskletStep做同样的TaskletStep呢? 以下代码不起作用: