我為 spring batch 創(chuàng)建了一個(gè)小的 hello world 項(xiàng)目:構(gòu)建.gradle:buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE") }}apply plugin: 'java'apply plugin: 'eclipse'apply plugin: 'idea'apply plugin: 'org.springframework.boot'apply plugin: 'io.spring.dependency-management'bootJar { baseName = 'gs-batch-processing' version = '0.1.0'}repositories { mavenCentral()}sourceCompatibility = 1.8targetCompatibility = 1.8dependencies { compile("org.springframework.boot:spring-boot-starter-batch") compile("org.postgresql:postgresql") compile("org.springframework.boot:spring-boot-starter-data-jpa") //to fix exception on startup //compile('org.hibernate:hibernate-core:5.4.2.Final') testCompile("junit:junit")}配置:@Configuration@EnableBatchProcessingpublic class BatchConfiguration { @Autowired public JobBuilderFactory jobBuilderFactory; @Autowired public StepBuilderFactory stepBuilderFactory; @Autowired private DbPersonWriter dbPersonWriter; @Autowired private ToLowerCasePersonProcessor toLowerCasePersonProcessor; @Value("${app.users-location}") Resource csvResource; @Bean public Job job() { return jobBuilderFactory.get("myJob") .incrementer(new RunIdIncrementer()) .flow(csvToDataBaseStep()) .end() .build(); } private Step csvToDataBaseStep() { return stepBuilderFactory.get("csvToDatabaseStep") .<Person, Person>chunk(100) .reader(csvPersonReader()) .processor(toLowerCasePersonProcessor) .writer(dbPersonWriter) .build(); }
如果缺少 hibernate 依賴項(xiàng),方法 org.postgresql.jdbc
叮當(dāng)貓咪
2023-05-17 16:59:06