gpt4 book ai didi

playframework - play2-elasticsearch 与 Play Framework 2.1.3

转载 作者:行者123 更新时间:2023-12-02 22:26:13 24 4
gpt4 key购买 nike

我正在尝试将我的应用程序从 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

所以我认为 a similar question 中解释的案例不是我的情况。

请帮我解决这个问题。

更新:

我的 Elasticsearch 配置:
## 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

最佳答案

配置看起来不错。

关于堆栈跟踪,似乎 Ebean 插件正在尝试访问 models.indexing.ClientIndex启动类和 Elasticsearch 配置尚不可用,这就是为什么 NullPointerException被抛出。

我建议两种选择:

  • 将您的“索引”类移到 ebean 扫描的包之外(由配置键 ebean.default 定义)
  • 或通过在 conf/play.plugins 中设置小于 300 的数字,在 ebean 之前加载 elasticsearch 模块com.github.cleverage.elasticsearch.plugin.IndexPlugin 前面的文件.
  • 关于playframework - play2-elasticsearch 与 Play Framework 2.1.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18490093/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com