@khmatsunaga

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

SpringBatchの実行でエラーになっているが原因が分かりません。

Q&A

Closed

SpringBatchの実行でエラーになっているが原因が分かりません。

仕事でSpringBatchを作る必要があり、
下記のソースを実行すると、失敗しエラーとなりました。

--ソース--
package com.example.demo;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
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.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableBatchProcessing
@Configuration
public class BatchConfig {
@Autowired private HelloFirst HelloFirst;
@Autowired private HelloSecond HelloSecond;
@Autowired private JobBuilderFactory jobBuilderFactory;
@Autowired private StepBuilderFactory stepBuilderFactory;

@Bean
public Job testJob1(Step testStep1,Step testStep2) {
    return jobBuilderFactory.get("testJob")
        .incrementer(new RunIdIncrementer())
    .start(testStep1)
    .next(testStep2)
            .build();
}

@Bean
public Step testStep1() {
    return stepBuilderFactory.get("TestStep11")
            .tasklet(HelloFirst)
            .build();
}
@Bean
public Step testStep2() {
    return stepBuilderFactory.get("TestStep21")
            .tasklet(HelloSecond)
            .build();
}

}

--エラー内容--
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.


APPLICATION FAILED TO START


Description:

Field jobBuilderFactory in com.example.demo.BatchConfig required a bean of type 'org.springframework.batch.core.configuration.annotation.JobBuilderFactory' that could not be found.

The injection point has the following annotations:

  • @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:
Consider defining a bean of type 'org.springframework.batch.core.configuration.annotation.JobBuilderFactory' in your configuration.


「org.springframework.batch.core.configuration.annotation.JobBuilderFactory」の Beanを定義することを検討してください。
という内容です
Beanの定義はしているはずなのですか、何がエラーなのか分かりません。
エラーの原因がおわかりになる方がいらっしゃいましたら、ご教授いただけないでしょうか。

0 likes

1Answer

Your answer might help someone💌