1
すべてのプログラムはこちらです。SpringBootプロジェクトでAutowiredできません
public class MyBatchJob implements Tasklet {
static Logger logger = Logger.getLogger("MyBatch");
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;
@Autowired
private SampleTableRepository sampleTableRepo;
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)
throws Exception {
SampleTableEntity sampleTable = new SampleTableEntity();
sampleTable.setName("test name");
sampleTable.setStatus(100);
entityManager.persist(sampleTable);
sampleTableRepo.findAll();
System.out.println("Created SampleTableEntity=" + sampleTable.getId());
return RepeatStatus.FINISHED;
}
}
https://github.com/horitaku1124/spring_batch_sample/tree/master/SpringBatchSample1
Main.java
public class Main {
public static void main(String[] args) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
{
JobLauncher jobLauncher = context.getBean("jobLauncher", JobLauncher.class);
Job job = context.getBean("myJob1", Job.class);
JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Job Exit Status : " + execution.getStatus());
}
}
}
MyBatchJob.javaこのMain.javaを実行し、私はこのエラーを得ました。
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.spring.repository.SampleTableRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
EntityManagerはうまくいきます。 Autowired SampleTableRepositoryを実行するとエラーが発生します。 この問題をどのように解決すればよいですか?
私はこのプロパティを追加しました ' ' しかし別のエラーが発生しました。 '原因:org.xml.sax.SAXParseException; lineNumber:34; columnNumber:70; cvc-complex-type.2.4.c:一致するワイルドカードは厳密ですが、要素 'jpa:repositories'の宣言が見つかりません。 この問題をどのように修正すればよいですか? –