###前提・実現したいこと
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側での対処等も思い浮かびません。
図々しいお願いではありますが、詳しく教えていただけると幸いです。
すみませんが、よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/25 06:45