【问题标题】:Spring batch : Cannot determine embedded database driver class for database type NONESpring批处理:无法确定数据库类型NONE的嵌入式数据库驱动程序类
【发布时间】:2018-07-10 02:29:57
【问题描述】:

我刚开始学习 Spring Batch,之前没有 Spring Batch 的经验。

我从 start.spring.io 下载了一个模板并选择了以下

在此之后,我将项目导入 IntelliJ IDE 并进行了以下更改

添加了作业配置类:

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


    }

}

这就是我的入门类的样子

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

我没有触及或修改任何类\配置。但是当我运行该应用程序时,我收到以下消息:

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).

我可以做些什么来修复这个错误?

【问题讨论】:

  • 嗯,你想要什么样的数据库?嵌入式还是外部?你查过谷歌吗?我尝试了“支持的 spring-batch 嵌入式数据库”,我得到了this。其中列出了支持 HSQL、H2 和 Derby。

标签: java spring spring-boot intellij-idea spring-batch


【解决方案1】:

解决这个错误有两种方法:

方法一:

尝试添加以下注释:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

示例:

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

方法二:

您可以在application.properties 文件中添加以下行

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

【讨论】:

    猜你喜欢
    • 2018-06-18
    • 2014-07-27
    • 2016-02-16
    • 2019-04-09
    • 2018-03-28
    • 2018-02-12
    • 2018-01-04
    • 1970-01-01
    相关资源
    最近更新 更多