Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 错误:类型为';的bean中需要字段作业;org.springframework.batch.core.Job';那是找不到的_Spring Boot_Spring Batch - Fatal编程技术网

Spring boot 错误:类型为';的bean中需要字段作业;org.springframework.batch.core.Job';那是找不到的

Spring boot 错误:类型为';的bean中需要字段作业;org.springframework.batch.core.Job';那是找不到的,spring-boot,spring-batch,Spring Boot,Spring Batch,我是SpringBatch的初学者,我用它开发了一个简单的项目。我得到了错误 Description: Field job in com.example.demo.DemoApplication required a bean of type 'org.springframework.batch.core.Job' that could not be found. Action: Consider defining a bean of type 'org.springframework.bat

我是SpringBatch的初学者,我用它开发了一个简单的项目。我得到了错误

Description:
Field job in com.example.demo.DemoApplication required a bean of type 
'org.springframework.batch.core.Job' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.batch.core.Job' in your 
configuration.
这是我的代码,我只有一个类:

'package com.example.demo;


import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@SpringBootApplication
@EnableScheduling
@EnableBatchProcessing
public class DemoApplication {



@Autowired
private JobLauncher jobLauncher;


 @Autowired
 private Job job;

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


 @Scheduled(cron = "0 */1 * * * ?")
    public void perform() throws Exception 
    {
        JobParameters params = new JobParametersBuilder()
                .addString("JobID", String.valueOf(System.currentTimeMillis()))
                .toJobParameters();
        jobLauncher.run(job, params);
    }

 }

感谢您帮助我找到此错误的主要原因

您的应用程序上下文中似乎没有定义
作业
bean,或者Spring Boot找不到该作业


确保定义批处理作业的配置类位于Spring Boot应用程序扫描的包(或子包)中(根据示例为
com.example.demo
)。

检查是否将Spring注释添加到作业中@服务如果是服务类, @RestController如果是RESTAPI,@Repository如果是repo