首页 > 解决方案 > 无法自动接线。找不到“InstructionRepository”类型的 bean

问题描述

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

InstructionRepository 在 jar 中使用 @Repository 注解进行了注解,是一个扩展 Spring Data Interface 的 Interface

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);
    }
}

指令库

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

}

我们如何修复错误并能够启动 Spring Boot 应用程序?

任何建议表示赞赏。

标签: spring-bootspring-data-jpajavabeansautowired

解决方案


您需要添加 @EnableCouchbaseRepositories以启用 repo 构建,例如AppConfig.


推荐阅读