最近使用ElasticSearch的时候遇到以下的异常
2017-07-27 16:06:48.482 MessageHandler - message process error: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.common.xcontent.smile.SmileXContent at org.elasticsearch.common.xcontent.XContentFactory.contentBuilder(XContentFactory.java:124) ~[elasticsearch-2.3.4.jar:2.3.4] at org.elasticsearch.action.support.ToXContentToBytes.buildAsBytes(ToXContentToBytes.java:62) ~[elasticsearch-2.3.4.jar:2.3.4] at org.elasticsearch.action.search.SearchRequest.source(SearchRequest.java:250) ~[elasticsearch-2.3.4.jar:2.3.4] at org.elasticsearch.action.search.SearchRequestBuilder.beforeExecute(SearchRequestBuilder.java:1027) ~[elasticsearch-2.3.4.jar:2.3.4] at org.elasticsearch.action.search.SearchRequestBuilder.beforeExecute(SearchRequestBuilder.java:50) ~[elasticsearch-2.3.4.jar:2.3.4] at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86) ~[elasticsearch-2.3.4.jar:2.3.4] at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56) ~[elasticsearch-2.3.4.jar:2.3.4] at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:64) ~[elasticsearch-2.3.4.jar:2.3.4] at org.nlpcn.es4sql.query.SqlElasticSearchRequestBuilder.get(SqlElasticSearchRequestBuilder.java:43) ~[elasticsearch-sql-2.3.4.1.jar:na] at com.iteblog.dao.impl.EsDaoImpl.explainSql(EsDaoImpl.java:63) ~[EsDaoImpl.class:na] at Listener1.onMessage(Listener1.java) ~[na:na] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_45] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_45] at iteblog.concurrent.QueueWorker.run(QueueWorker.java:95) [common-concurrent-9.0.6.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_45] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_45] at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
找了大半天也没发现哪里有问题,后来想到 elasticSearch 里面依赖了 jackson-xxx 相关的包,根据之前的经验,如果这个包不兼容的话会出现各种奇怪的问题。于是我找了下,果然发现在编译好的项目里面带了一个 jackson-core-2.3.0.jar,如下:
-rw-r--r-- 1 iteblog iteblog 35058 Mar 9 15:32 jackson-annotations-2.3.0.jar -rw-r--r-- 1 iteblog iteblog 258917 Mar 2 11:32 jackson-core-2.3.0.jar -rw-r--r-- 1 iteblog iteblog 914028 Mar 9 15:32 jackson-databind-2.3.0.jar
然后我翻了一下elasticsearch-2.3.4.jar中对 jackson-core 包的依赖,发现版本是
-rw-r--r-- 1 iteblog iteblog 35058 Mar 9 15:32 jackson-annotations-2.6.6.jar -rw-r--r-- 1 iteblog iteblog 258917 Mar 2 11:32 jackson-core-2.6.6.jar -rw-r--r-- 1 iteblog iteblog 914028 Mar 9 15:32 jackson-databind-2.6.6.jar
重启应用程序,终于发现出现正常了。。
记得我之前在使用 Zeppelin 的时候也遇到过类似这种问题,《Apache Zeppelin & Spark 解析Json异常》。这种问题太坑了,很难Debug到。。所以下次遇到类似的问题先看下是否依赖了 jackson-xxx 相关包。
本博客文章除特别声明,全部都是原创!原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【elasticsearch:Could not initialize class org.elasticsearch.common.xcontent.smile.SmileXContent】(https://www.iteblog.com/archives/2216.html)