java - Spring 批 : Cannot determine embedded database driver class for database type NONE

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

我刚开始学习 Spring Batch,之前没有使用过 Spring Batch。

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

enter image description here

在此之后,我将项目导入 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).

我该如何解决这个错误?

最佳答案

要解决此错误,有两种方法:

方法一:

尝试添加以下注释:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

例子:

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

方法二:

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

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

关于java - Spring 批 : Cannot determine embedded database driver class for database type NONE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48534390/

相关文章:

java - 是否可以设置 Selenium Webdriver 在遇到错误时进行屏幕捕获

spring - 使用 Hibernate 和 Oracle 找不到架构

java - 了解添加到数组方法的逻辑

java - 改造 2 和 GSON java.lang.IllegalArgumentException : Field map contained null value for key

java - 从服务器端添加 jsp 指令

java - 为什么这个初始化和配置的 Dispatcher Servlet 不处理任何请求?

java - bean 未知与春

java - Spring AOP 在 Spring Boot 2.1.6 应用程序中没有被调用

java - 使用存储过程快速从sql server读取百万条记录并使用java和spring boot将其写入csv

java - 部署 Spring Boot 应用程序时的 Swagger UI 错误验证