0
我最近開始使用Spring批處理(而且對Java很新),現在我試圖創建一個在數據庫中創建表的tasklet。使用StepBuilder創建tasklet時「無法反序列化執行上下文」
@EnableBatchProcessing
@SpringBootApplication
public class Configure {
public static void main(String[] args)
{
SpringApplication.run(Configure.class, args);
}
@Bean
public Job AggregateTransactionsFromDatabaseToXML(JobBuilderFactory jobBuilderFactory,
StepBuilderFactory stepBuilderFactory,
Tasklets tasklets){return jobBuilderFactory.get("etl")
.incrementer(new RunIdIncrementer())
.start(tasklets.createTempTable(null, null))
.build();}
@Configuration
static class Tasklets{
@Bean
Step createTempTable(DataSource dataSource, StepBuilderFactory stepBuilderFactory) {
StepBuilder createTempTable = stepBuilderFactory.get("create temp table");
String sql = "CREATE TABLE DatabaseName.TableName\n" +
"(\n" +
" column1 VARCHAR(255) NOT NULL,\n" +
" column2 DATE NOT NULL,\n" +
" column3 DECIMAL NOT NULL,\n" +
" column4 BIGINT NOT NULL,\n" +
" column5 BIGINT NOT NULL\n" +
")";
return createTempTable.tasklet((contribution, chunkContext) -> {
new JdbcTemplate(dataSource).execute(sql);
return RepeatStatus.FINISHED;
})
.allowStartIfComplete(true)
.build();
}
}
}
我得到一個錯誤:Caused by: java.lang.IllegalArgumentException: Unable to deserialize the execution context.
我不知道這是怎麼可能的。
我在網上查找StepBuilder的例子,但找不到任何有用的工作。 TaskletStepBuilder example和 Reader en Writer example
我使用StepBuilder是否錯誤?任何人都知道如何解決這個問題?
問題已解決:我沒有配置spring應用程序上下文。這顯然很重要。
你使用什麼源代碼的教程(如果你能提供的話)?另外,分享完整的代碼。你是否使用過像Spring Boot這樣的框架?你如何設置你的數據源和你使用的數據庫類型? –
我正在使用spring引導和mysql。數據源在application.properties內部配置(它在我運行的其他步驟上工作,而不是這個[https://github.com/EBIvariation/examples/blob/master/spring-batch-dynamic-workflow/src/main/java /embl/ebi/variation/examples/dynamicworkflow/SimpleDeciderConfiguration.java]and [https://aboullaite.me/spring-batch-tutorial-with-spring-boot/] – teuno
糾正你的鏈接,都給404。包括有問題如果可能, –