CDI 統合
Spring Data Elasticsearch リポジトリは、CDI 機能を使用して設定することもできます。
例 1: CDI を使用した Spring Data Elasticsearch リポジトリ
class ElasticsearchTemplateProducer {
@Produces
@ApplicationScoped
public ElasticsearchOperations createElasticsearchTemplate() {
// ... (1)
}
}
class ProductService {
private ProductRepository repository; (2)
public Page<Product> findAvailableBookByName(String name, Pageable pageable) {
return repository.findByAvailableTrueAndNameStartingWith(name, pageable);
}
@Inject
public void setRepository(ProductRepository repository) {
this.repository = repository;
}
}
1 | Elasticsearch オペレーションの章で使用されているのと同じ呼び出しを使用してコンポーネントを作成します。 |
2 | CDI フレームワークにリポジトリをクラスに挿入させます。 |