【发布时间】:2019-04-09 18:39:27
【问题描述】:
@SpringBootApplication 公共类 ReactiveCouchbaseExample1Application {
@Bean
CommandLineRunner employees(ApplicationContext context) {
EmployeeRepository repository = context.getBean(EmployeeRepository.class);
return args -> {
repository
.deleteAll()
.subscribe(null,null,()->{
Stream.of(new Employees(UUID.randomUUID().toString(), "Nikhil", 23, 3000L),
new Employees(UUID.randomUUID().toString(), "Shubham", 23, 3000L),
new Employees(UUID.randomUUID().toString(), "Anshul", 23, 3000L))
.forEach(employee->{
repository.save(employee)
.subscribe(System.out::println);
});
});
};
}
public static void main(String[] args) {
SpringApplication.run(ReactiveCouchbaseExample1Application.class, args);
}
我想在我的应用程序上下文加载后立即运行这段逻辑,但是当我启动我的应用程序时,它显示了这个错误。
Method employees in com.reactive.reactivecouchbaseexample1.ReactiveCouchbaseExample1Application required a bean of type 'com.reactive.repository.EmployeeRepository' that could not be found.
谁能告诉我如何在 CommandLineRunner 中创建存储库 bean。 我也用谷歌搜索了它,但找不到任何答案。
这是我的仓库
@Repository
public interface EmployeeRepository extends
ReactiveCouchbaseRepository<Employees, String>{
}
【问题讨论】:
-
显示整个 ReactiveCouchbaseExample1Application.class
标签: spring spring-data