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'요소에 대한 선언을 찾을 수 없습니다. 이 문제점을 어떻게 해결해야합니까? –