簡體   English   中英

Spring批處理:無法確定數據庫類型NONE的嵌入式數據庫驅動程序類

[英]Spring batch : Cannot determine embedded database driver class for database type NONE

我剛開始學習Spring批處理,沒有任何Spring批處理的經驗。

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

我該怎么做才能解決此錯誤?

要解決此錯誤,有兩種方法:

方法1:

嘗試添加以下注釋:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

例:

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

方法2:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM