我有一个Spring Boot应用程序,该应用程序使用Spring JPA连接到数据库并检索数据进行处理。当我尝试使用自动布线时,出现以下错误。有人可以请问一下。
@Component
public interface PrintJobItemRepo extends CrudRepository<PrintJobItem, Integer> {
List<PrintJobItem> findByPrintStatusEquals(String printStatus );
}
在此类中调用此组件
public class ReadInputFile implements Tasklet {
private Resource inputResource;
private String targetDirectory;
@Autowired
private PrintJobItemRepo pjr;
}
错误如下
Error creating bean with name 'scopedTarget.decompressTasklet': Unsatisfied dependency expressed
through field 'pjr'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'com.printbatch.repo.PrintJobItemRepo' available: expected at least 1 bean which qualifies as
autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
从PrintJobItemRepo中删除@Component。 ReadInputFile是托管bean吗?如果不是,则应使用Component,Service对其进行批注,或使其成为Bean,因此它必须成为托管对象。 Spring只能将托管bean注入另一个托管bean中。