1

I am playing with a simple batch processing and I have a problem with a DataSource configuration despite having an H2 dependency.

Output from the console:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

My classes operates on Strings and use:

org.springframework.batch.item.ItemProcessor;
org.springframework.batch.item.ItemReader;
org.springframework.batch.item.ItemWriter;

Main

@SpringBootApplication   
public class Boo2BatchApplication {

    public static void main(String[] args) {
        SpringApplication.run(Boo2BatchApplication.class, args);
    }
}

Config:

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();
    }

}
marekmuratow
  • 394
  • 2
  • 13
  • 2
    did you add h2 driver to your project? – Alireza Khajavi Aug 26 '18 at 09:43
  • Possible duplicate of [How to java-configure separate datasources for spring batch data and business data? Should I even do it?](https://stackoverflow.com/questions/25256487/how-to-java-configure-separate-datasources-for-spring-batch-data-and-business-da) –  Aug 26 '18 at 09:46
  • The H2 dependency is sufficient. No additional configuration is needed. – marekmuratow Aug 26 '18 at 10:15

1 Answers1

2

When a Database like H2 is on the path the DataSource is configured by default (as @Alireza Khajavi said). No additional configuration is needed. My classpath was messed up and the dependency from a pom file was not available during startup.

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
marekmuratow
  • 394
  • 2
  • 13