3

I just started learning spring batch with no prior experience of Spring batch.

I downloaded a template from start.spring.io and selected following

enter image description here

After this I imported the project in IntelliJ IDE and made following changes

Added a job configuration class:

package io.spring.helloworld.configuration;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
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.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration  //For spring configuration
@EnableBatchProcessing  //bootstrap all the infra needed to run spring batch
public class jobConfiguration {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;


    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .tasklet(new Tasklet() {
                    @Override
                    public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
                        System.out.println("Hello World");
                        return RepeatStatus.FINISHED;
                    }
                }).build();
    }

    @Bean
    public Job HelloWorld() {
        return jobBuilderFactory.get("HelloWorldJob")
                .start(step1())
                .build();


    }

}

and this is how my entry class looks

package io.spring.helloworld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication

public class HelloWorldApplication {

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

        System.exit(0);
    }
}

I have not touched or modified any class\configuration. But when i run the app, I get following message:

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

What Can i do to fix this error?

1
  • Well, what kind of database do you want? Embedded or external? Have you checked google? I tried "supported spring-batch embedded databases", and I got this. Which lists HSQL, H2 and Derby as being supported. Commented Jan 31, 2018 at 4:24

1 Answer 1

1

To resolve this error there are two methods:

Method 1:

Try adding below annotation:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

example:

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class HelloWorldApplication {
-----
}

Method 2:

you can add the below line in application.properties file

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.