尝试在Spring Boot应用程序中创建一个bean,但是收到以下错误“无法自动装配。找不到'指令存储库'类型的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启动应用程序?
任何建议赞赏。
您需要添加@EnableCouchbaseRepositories
以启用repo构建,例如AppConfig
。