2

我正在尝试将我的应用程序从 Play 2.0.3 迁移到最新版本的 Play Framework (2.1.3) 和 play2-elasticsearch 插件。

根据插件自述文件我使用 0.7-SNAPSHOT 版本。

我的 sbt 是:

"com.github.cleverage" % "elasticsearch_2.9.1" % "0.4.1"

并成为:

"com.clever-age" % "play2-elasticsearch" % "0.7-SNAPSHOT"

我在应用程序启动时收到 NullPointerException :

play.api.Configuration$$anon$1: Configuration error[Cannot register class [models.indexing.ClientIndex] in Ebean server]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:81) ~[play_2.10.jar:2.1.3]
    at play.api.Configuration.reportError(Configuration.scala:559) ~[play_2.10.jar:2.1.3]
    at play.Configuration.reportError(Configuration.java:298) ~[play_2.10.jar:2.1.3]
    at play.db.ebean.EbeanPlugin.onStart(EbeanPlugin.java:71) ~[play-java-ebean_2.10.jar:2.1.3]
    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:68) ~[play_2.10.jar:2.1.3]
    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:68) ~[play_2.10.jar:2.1.3]
    at scala.collection.immutable.List.foreach(List.scala:309) ~[scala-library.jar:na]
    at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:68) ~[play_2.10.jar:2.1.3]
    at play.api.Play$$anonfun$start$1.apply(Play.scala:68) ~[play_2.10.jar:2.1.3]
    at play.api.Play$$anonfun$start$1.apply(Play.scala:68) ~[play_2.10.jar:2.1.3]
    at play.utils.Threads$.withContextClassLoader(Threads.scala:18) ~[play_2.10.jar:2.1.3]
    at play.api.Play$.start(Play.scala:67) ~[play_2.10.jar:2.1.3]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:141) ~[play_2.10.jar:2.1.3]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:114) ~[play_2.10.jar:2.1.3]
    at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:114) ~[play_2.10.jar:2.1.3]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.1.3]
    at scala.util.Either$RightProjection.flatMap(Either.scala:523) ~[scala-library.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.1.3]
    at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:104) ~[play_2.10.jar:2.1.3]
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library.jar:na]
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.7.0_09]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.7.0_09]
    at java.lang.Thread.run(Unknown Source) [na:1.7.0_09]
Caused by: java.lang.ExceptionInInitializerError: null
    at com.github.cleverage.elasticsearch.Index.getIndexPath(Index.java:37) ~[play2-elasticsearch-0.7-SNAPSHOT.jar:0.7-SNAPSHOT]
    at com.github.cleverage.elasticsearch.Index$Finder.<init>(Index.java:144) ~[play2-elasticsearch-0.7-SNAPSHOT.jar:0.7-SNAPSHOT]
    at models.indexing.ClientIndex.<clinit>(ClientIndex.java:18) ~[na:na]
    at java.lang.Class.forName0(Native Method) ~[na:1.7.0_09]
    at java.lang.Class.forName(Unknown Source) ~[na:1.7.0_09]
    at play.db.ebean.EbeanPlugin.onStart(EbeanPlugin.java:69) ~[play-java-ebean_2.10.jar:2.1.3]
    ... 21 common frames omitted
Caused by: java.lang.NullPointerException: null
    at com.github.cleverage.elasticsearch.IndexService.<clinit>(IndexService.java:43) ~[play2-elasticsearch-0.7-SNAPSHOT.jar:0.7-SNAPSHOT]
    ... 27 common frames omitted

所以我认为在类似问题中解释的案例不是我的案例。

请帮我解决这个问题。

更新:

我的弹性搜索配置:

## ElasticSearch Configuration
##############################
## define local mode or not
elasticsearch.local=true

## list clients
# ex : elasticsearch.client="192.168.0.46:9300,192.168.0.47:9300"

## Name of the index
elasticsearch.index.name="play2-elasticsearch"

## Custom settings to apply when creating the index (optional)
# elasticsearch.index.settings="{ analysis: { analyzer: { my_analyzer: { type: \"custom\", tokenizer: \"standard\" } } } }"

## define package or class separate by commas for loading @IndexType and @IndexMapping information
elasticsearch.index.clazzs="models.*"

## show request & result json of search request in log
elasticsearch.index.show_request=true
4

1 回答 1

2

配置看起来不错。

关于堆栈跟踪,似乎 Ebean 插件正在尝试models.indexing.ClientIndex在启动时访问该类,而 Elasticsearch 配置尚不可用,这NullPointerException就是抛出 a 的原因。

我建议两种选择:

  • 将您的“索引”类移到 ebean 扫描的包之外(由配置键定义ebean.default
  • conf/play.plugins或者通过在你的文件中设置一个低于 300 的数字来加载 ebean 之前的 elasticsearch 模块com.github.cleverage.elasticsearch.plugin.IndexPlugin
于 2013-08-28T14:44:28.147 回答