本文主要是介绍Spring Data访问Elasticsearch----CDI集成,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Spring Data访问Elasticsearch----CDI集成
Spring Data Elasticsearch存储库也可以使用CDI功能进行设置。
例1:Spring Data Elasticsearch库使用CDI
class ElasticsearchTemplateProducer {@Produces@ApplicationScopedpublic ElasticsearchOperations createElasticsearchTemplate() {// ... --------1 }
}class ProductService {private ProductRepository repository; --------2 public Page<Product> findAvailableBookByName(String name, Pageable pageable) {return repository.findByAvailableTrueAndNameStartingWith(name, pageable);}@Injectpublic void setRepository(ProductRepository repository) {this.repository = repository;}
}1. 使用与[Elasticsearch操作](https://blog.csdn.net/gabriel_wang_sh/article/details/136813482)章节相同的调用创建组件。
2. 让CDI框架将Repository注入到类中。
这篇关于Spring Data访问Elasticsearch----CDI集成的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!