我刚开始学习springbatch,之前没有springbatch的经验。
我从start.spring.io下载了一个模板并选择了以下内容
在此之后,我在intellijide中导入了这个项目,并做了以下更改
添加了作业配置类:
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条答案
按热度按时间7gs2gvoe1#
要解决此错误,有两种方法:
方法1:
尝试添加以下注解:
例子:
方法2:
您可以在中添加下面的行
application.properties
文件