我正在使用Java for Play,我正在尝试使用弹性搜索使EBean工作。我不需要或不想要数据库连接,因为我不打算将数据存储在数据库中,只能存储在elasticsearch中。
这是我的application.conf
ebean.docstoreonly=true
ebean.docstore.url="http://dockermachine:9200"
ebean.docstore.active=true
ebean.docstore.generateMapping=true
ebean.docstore.dropCreate=true
不幸的是,当我运行项目时,我收到以下错误:
[error] java.lang.RuntimeException: com.typesafe.config.ConfigException$WrongType: conf\application.conf: 33: docstoreonly has type BOOLEAN rather than LIST
[error] at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:163)
[error] at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:174)
[error] at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:188)
[error] at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:193)
[error] at com.typesafe.config.impl.SimpleConfig.getList(SimpleConfig.java:262)
[error] at com.typesafe.config.impl.SimpleConfig.getHomogeneousUnwrappedList(SimpleConfig.java:348)
[error] at com.typesafe.config.impl.SimpleConfig.getStringList(SimpleConfig.java:406)
[error] at play.db.ebean.EbeanParsedConfig.lambda$parseFromConfig$5(EbeanParsedConfig.java:72)
[error] at java.util.Map.forEach(Map.java:630)
[error] at play.db.ebean.EbeanParsedConfig.parseFromConfig(EbeanParsedConfig.java:66)
[error] at play.db.ebean.EbeanParsedConfig.parseFromConfig(EbeanParsedConfig.java:47)
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:28)
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:21)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$4(PlayEbean.scala:153)
[error] at play.ebean.sbt.PlayEbean$.withClassLoader$1(PlayEbean.scala:130)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$1(PlayEbean.scala:150)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error] at sbt.std.Transform$$anon$4.work(System.scala:66)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:271)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] at java.lang.Thread.run(Thread.java:748)
[error] java.lang.RuntimeException: com.typesafe.config.ConfigException$WrongType: conf\application.conf: 33: docstoreonly has type BOOLEAN rather than LIST
[error] at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:163)
[error] at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:174)
[error] at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:188)
[error] at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:193)
[error] at com.typesafe.config.impl.SimpleConfig.getList(SimpleConfig.java:262)
[error] at com.typesafe.config.impl.SimpleConfig.getHomogeneousUnwrappedList(SimpleConfig.java:348)
[error] at com.typesafe.config.impl.SimpleConfig.getStringList(SimpleConfig.java:406)
[error] at play.db.ebean.EbeanParsedConfig.lambda$parseFromConfig$5(EbeanParsedConfig.java:72)
[error] at java.util.Map.forEach(Map.java:630)
[error] at play.db.ebean.EbeanParsedConfig.parseFromConfig(EbeanParsedConfig.java:66)
[error] at play.db.ebean.EbeanParsedConfig.parseFromConfig(EbeanParsedConfig.java:47)
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:28)
[error] at play.db.ebean.ModelsConfigLoader.apply(ModelsConfigLoader.java:21)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$4(PlayEbean.scala:153)
[error] at play.ebean.sbt.PlayEbean$.withClassLoader$1(PlayEbean.scala:130)
[error] at play.ebean.sbt.PlayEbean$.$anonfun$configuredEbeanModels$1(PlayEbean.scala:150)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error] at sbt.std.Transform$$anon$4.work(System.scala:66)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:271)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] at java.lang.Thread.run(Thread.java:748)
[error] (module1 / Compile / playEbeanModels) com.typesafe.config.ConfigException$WrongType: conf\application.conf: 33: docstoreonly has type BOOLEAN rather than LIST
[error] (module2 / Compile / playEbeanModels) com.typesafe.config.ConfigException$WrongType: conf\application.conf: 33: docstoreonly has type BOOLEAN rather than LIST
[error] Total time: 4 s, completed Apr 23, 2018 5:06:00 PM
我正在关注github上发现的示例:https://github.com/ebean-orm-examples/example-elasticsearch-only
它说ebean.docstoreonly
应该设置为true,但它似乎需要List。
我正在使用sbt-play-ebean
插件
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.1.0")
在内部使用EBean版本11.7.x
我的build.sbt依赖于这个ebean-elastic组件:
"io.ebean" % "ebean-elastic" % "11.15.1"
在EBean中可能只使用elasticsearch,还是应该使用其他方法,比如elasticsearch官方java sdk?
答案 0 :(得分:0)
经过长时间的反复试验,以下是解决方案:
似乎application.conf
不是我应该存储ebean属性的地方。它应该是一个单独的文件,位于application.conf
所在的同一目录中。
文件应命名为ebean.properties
:
ebean.elasticsearch.docStoreOnly=true
ebean.elasticsearch.docstore.url=http://dockermachine:9200
ebean.elasticsearch.docstore.active=true
ebean.elasticsearch.docstore.generateMapping=true
ebean.elasticsearch.docstore.dropCreate=true
ebean.elasticsearch.docstore.pathToResources=conf
这里有几点需要注意:
ebean.properties
在这里是必要的,因为application.conf
无法解释其未知的键/值对,并且默认为LIST。这应该是sbt-play-ebean
插件的工作,但似乎插件已经过时(有人可能会给我更好的解释)ebean.docstoreonly
错了。这是它的正确框图:ebean.docStoreOnly
。src/main/resources
。这将在Maven构建中工作,但需要使用sbt构建工具和播放框架,该框架需要进入项目(或子模块)的/conf
文件夹。这就是我需要覆盖ebean.elasticsearch.docstore.pathToResources
"com.h2database" % "h2" % "1.4.196"
。不知道为什么(因为我没有任何支持数据库),但我得到的是ClassNotFoundExceptions。docStoreOnly
然后ebean将不再在实际数据库中进行任何写入。为了使其工作,您需要创建两个ebean服务器:一个仅连接到数据库,另一个仅与elasticsearch通信。就我而言,默认的ebeanserver仅用于数据库连接(没有进行任何更改),我默认访问它:EbeanServer db = Ebean.getDefaultServer();
。对于elasticsearch,我只需要配置单独的ebeanserver。这就是ebean.properties
elasticsearch
ebean
与其他配置设置之间的ebean.properties
(ebean服务器的名称)的原因。基本上,elasticsearch
定义了名为EbeanServer dbes = Ebean.getServer("elasticsearch");
的新ebean服务器。除此之外没有其他配置要求。在内部代码中,我只使用elasticsearch这样的ebean服务器:namespace airflow
{
public sealed partial class MainPage : Page
{
}
public MainPage()
{
}
private async void main_page_Loaded(object sender, RoutedEventArgs e)
{
param_perimetrala read = new param_perimetrala();
ora_start_perimetrala = read.start_perimetrala;
var mesaj = new MessageDialog(ora_start_perimetrala.ToString());
var res = await mesaj.ShowAsync();
}
}