spring-boot - 无法自动接线。找不到“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 应用程序?
任何建议表示赞赏。
解决方案
您需要添加 @EnableCouchbaseRepositories
以启用 repo 构建,例如AppConfig
.
推荐阅读
- python - How to sort a list with a custom key using the Python C API?
- android - 没有找到 void com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator() 的实现
- python - 使用 BeautifulSoup 和 Python 从多个标签中提取文本,例如具有类的 h1 和 p 标签
- wpf - Why does Unity “RegisterInstance” function in Prism Framework cann't return a single instance?
- javascript - Photoshop Extendscript: How to var check currently opened files and execute commands for certain filenames
- hyperledger-fabric - 对等通道创建 - 仅评估失败 0 个策略得到满足 Hyperledger Fabric
- asp.net-core-mvc - Serilog:为每个请求创建和跟踪唯一的日志上下文?
- python - 如何通过对两列施加的多个标准删除 Pandas 数据框中的行?
- regex - 如何从用户当前使用的任何代码编辑器中获取文本?- 自动
- html - 未在函数内定义的变量