質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Elasticsearch

Elasticsearchは、クラウド向けに構築された、RESTful な API を提供する分散型のサーチエンジンアプリケーションです。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

602閲覧

Java+Spring bootでElasticsearchに接続できない

rnosh

総合スコア171

Elasticsearch

Elasticsearchは、クラウド向けに構築された、RESTful な API を提供する分散型のサーチエンジンアプリケーションです。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

1グッド

1クリップ

投稿2017/09/19 09:39

編集2017/09/19 09:55

###前提・実現したいこと
Java+Spring bootでElasticsearchとデータのやり取りをするWebアプリを作っています。
Webの様々な記事を参考に実装し、接続確認のためにSpring bootを起動したところ
以下のエラーが発生しています。
※ソースコード上にエラーは発生していません。

###発生している問題・エラーメッセージ
スタックトレースが長いため、エラー位置の記載は省きます。(基本jar内で発生しています)

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'postServiceImpl': Unsatisfied dependency expressed through field 'postRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [com/EsAccesser.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin at ~中略~ Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [com/EsAccesser.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin ~中略~ Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [com/EsAccesser.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin ~中略~ Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [com/EsAccesser.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin ~中略~ Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin ~中略~ Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin

###ソースコード

Java;EsAccesser.java

1@Bean 2public ElasticsearchOperations elasticsearchTemplate() throws Exception{ 3 return new ElasticsearchTemplate(client()); 4} 5 6@Bean 7public Client client() throws Exception{ 8 TransportClient client = new PreBuiltTransportClient(Settings.EMPTY) 9 .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(env.getProperty("elasticsearch.host")), 9200)) 10 .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(env.getProperty("elasticsearch.host")), 9300)); 11 return client; 12}

###試したこと

  • Elasticsearchのdependencyを追記

⇒5.5.2ではビルドエラー、2.4.5ではビルドエラーはないが、上記と同一のエラーにさし戻り

  • エラーの最下部のCaused byに記載されているorg.elasticsearch.plugins.ActionPluginをdependencyにダメもとで記載しようと試みるも

artifactIdが不明で断念。
⇒そもそも存在する?

  • ソースコードのTransportClient client = new Pre~の箇所でのエラーがスタックトレースから確認できたので、

PreBuiltTransportClientを変更
⇒ネットにあったサンプルをもとに、new TransportClient();と実装するが、引数Injectorが必要とエラー。
Injectorが自力では解決できず。。。

###バージョン
Java :8(jdk1.8.1_144)
Elasticsearch:5.5.2
Spring boot :1.5.7.RELEASE

知りたいこと

上記バージョンの組み合わせで構築することは可能でしょうか?
一部StackOverFlowを確認すると、Elasticsearch5.5.xに対してSpring bootが対応していないようにも見受けられました。
ただ、最初のエラー発生時点で、pom.xmlにElasticsearchのバージョンは明示していませんでしたので、
そのあたりも含めてどう実装したらいいのか完全に詰まってしまっている状況です。
※pom.xmlのElasticsearchに関する記載は、
spring-boot-starter-data-elasticsearchとelasticsearch.clientのdependencyです。

Spring bootでのElasticsearchの接続に関して詳しい方いらっしゃいましたご教示頂きたく思います。
スタックトレースもできる限り確認したつもりですが、如何せんSpring bootすら初めて触れるフレームワークのため
(今までStruts系のフレームワークしか経験がなく・・・)Spring boot側での対処等も思い浮かびません。
図々しいお願いではありますが、詳しく教えていただけると幸いです。
すみませんが、よろしくお願いします。

A-pZ👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

SpringBoot公式( https://github.com/spring-projects/spring-data-elasticsearch/wiki/Spring-Data-Elasticsearch---Spring-Boot---version-matrix )によると、ESの4以下なら対応はできますが、ES5からは下位互換していないため、対応していないようです。

投稿2017/09/20 05:21

A-pZ

総合スコア12011

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

rnosh

2017/09/25 06:45

やはりそうですよね。。。 Spring bootを2.0.0.MxにするかElasticsearchを落とすしかないようですね。 バージョン変更は厳しいのでやり方自体を変更することにしました。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問