无法自动接线。找不到“ InstructionRepository”类型的bean

时间:2019-03-26 20:28:11

标签: spring-boot spring-data-jpa javabeans autowired

尝试在SpringBoot应用程序中创建Bean,但出现以下错误“无法自动装配。找不到'InstructionRepository'类型的Bean。”

InstructionRepository在jar中使用@Repository批注进行批注,并且是扩展Spring数据接口的接口

ScheduleProcessor是一种方法

当我尝试通过传递基本包值来添加@ComponentScan批注时,错误消失了,但是当我启动应用程序时出现以下错误

com.xxx.resync.config.AppConfig中的构造函数的参数0需要找不到类型为“ com.xxx.repo.InstructionRepository”的bean。行动:考虑在您的配置中定义一个类型为“ com.xxx.repo.InstructionRepository”的bean。

@Configuration
@EnableAutoConfiguration
//@ComponentScan(basePackages = {"com.xxx.repo"})
public class AppConfig {

    @Value("${pssHttp.connectTimeout:3000}")
    private int connectTimeout;

    @Bean
    public RestTemplate getRestTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setConnectTimeout(connectTimeout);
        factory.setReadTimeout(connectTimeout);
        restTemplate.setRequestFactory(factory);
        return restTemplate;
    }

    @Bean
    public ScheduleUpdater getScheduleUpdater() {
        return new ScheduleUpdater(true);
    }

    @Bean
    public ScheduleProcessor scheduleProcessor(InstructionRepository instructionRepository, ScheduleUpdater scheduleUpdater) {
        return new ScheduleProcessor(instructionRepository, scheduleUpdater);
    }
}

InstructionRepository

@Repository
public interface InstructionRepository extends CouchbaseRepository<Instruction, String> {

}

我们如何解决该错误并能够启动Spring Boot应用程序?

任何建议表示赞赏。

1 个答案:

答案 0 :(得分:0)

您需要添加@EnableCouchbaseRepositories才能启用回购构建功能,例如到AppConfig

相关问题