【发布时间】:2019-02-01 03:31:48
【问题描述】:
我正在玩一个简单的批处理,尽管有 H2 依赖项,但我的 DataSource 配置有问题。
控制台输出:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
我的类在字符串上运行并使用:
org.springframework.batch.item.ItemProcessor;
org.springframework.batch.item.ItemReader;
org.springframework.batch.item.ItemWriter;
主要
@SpringBootApplication
public class Boo2BatchApplication {
public static void main(String[] args) {
SpringApplication.run(Boo2BatchApplication.class, args);
}
}
配置:
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableBatchProcessing
public class BatchConfig {
@Bean
public Step recordsStep(StepBuilderFactory stepBuilderFactory, RecordReader recordReader,
RecordProcessor<String> recordProcessor, RecordWriter recordWriter) {
return stepBuilderFactory.get("recordsSetp").<String, String>chunk(4).reader(recordReader)
.processor(recordProcessor).writer(recordWriter).build();
}
@Bean
Job recordsJob(JobBuilderFactory jobBuilderFactory, Step recordsStep) {
return jobBuilderFactory.get("recordsJob").start(recordsStep).build();
}
}
【问题讨论】:
-
你的项目中添加了h2驱动吗?
-
H2 依赖就足够了。无需额外配置。
标签: java spring spring-boot spring-batch datasource