【发布时间】: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