【问题标题】:Could not autowire. No beans of 'InstructionRepository' type found无法自动接线。找不到“InstructionRepository”类型的 bean
【发布时间】:2019-08-17 08:11:54
【问题描述】:

尝试在 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);
    }
}

指令库

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

}

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

任何建议表示赞赏。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 无法找到EnableJpaRepositories的maven依赖,我们如何添加这个依赖
    • 你必须使用@EnableCouchbaseRepositories
    • 在 AppConfig 中添加,但仍然有同样的错误。
    • 像这样添加@EnableJpaRepositories({"com.xxx.repo"})
    猜你喜欢
    • 2021-01-17
    • 2021-07-02
    • 2020-08-31
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多