我希望在Elasticsearch中执行单元测试,所以我正在使用
我遇到了这个异常。
在这一行代码上出现了异常。
我怀疑异常的原因可能是某些依赖版本的问题。请问有人可以帮忙确定正确的库依赖版本来解决问题吗?或者我还漏掉了其他什么东西吗? 编辑:从"org.apache.logging.log4j" % "log4j-core" % "2.8.2"中删除了"test"。 更新
Java-test-framework
。同时,我正在使用Elasticsearch-1.6.0
版本,并参考以下链接获取帮助:
https://www.elastic.co/guide/en/elasticsearch/reference/1.6/using-elasticsearch-test-classes.html
https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java
这是代码:class CampaignESTest extends ESTestCase {
def getCLient():MockTransportClient={
val settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), Files.createTempDir().toString())
.build();
val client = new MockTransportClient(settings);
client
}
}
class CampaignTestSearch extends PlaySpec{
val client=new CampaignESTest
val response = client.prepareSearch("dbtest")
.setTypes(CAMPAIGN_COLLECTION_NAME)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.addFields("uuid","campaignName","artworkID","activationDate","_source")
.setQuery(query)
.execute()
.actionGet()
}
我遇到了这个异常。
DeferredAbortedSuite:
[info] Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info] java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
[info] at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:101)
[info] at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:92)
[info] at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:78)
[info] at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:138)
[info] at testcontrollers.campaign.CampaignTestSerach.<init>(CampaignTestSerach.scala:40)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info] at java.lang.Class.newInstance(Class.java:442)
[info] ...
[info] Cause: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger
[info] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[info] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[info] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[info] at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:101)
[info] at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:92)
[info] at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:78)
[info] at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:138)
[info] at testcontrollers.campaign.CampaignTestSerach.<init>(CampaignTestSerach.scala:40)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info] ...
[error] Uncaught exception when running testcontrollers.campaign.CampaignTestSerach: java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
在这一行代码上出现了异常。
val client=new CampaignESTest
在 CampaignTestSearch
类中
以下是 build.sbt
文件中的依赖项
"org.slf4j" % "slf4j-api" % "1.6.4",
"org.elasticsearch" % "elasticsearch" % "1.6.0",
"org.elasticsearch.test" % "framework" % "5.0.0" % "test",
"org.apache.lucene" % "lucene-test-framework" % "4.10.4" % "test",
"com.carrotsearch.randomizedtesting" % "randomizedtesting-runner" % "1.6.0" % "test",
"org.apache.lucene" % "lucene-codecs" % "4.10.4" % "test",
"org.apache.logging.log4j" % "log4j-core" % "2.8.2" ,
"org.apache.lucene" % "lucene-expressions" % "4.10.4",
我怀疑异常的原因可能是某些依赖版本的问题。请问有人可以帮忙确定正确的库依赖版本来解决问题吗?或者我还漏掉了其他什么东西吗? 编辑:从"org.apache.logging.log4j" % "log4j-core" % "2.8.2"中删除了"test"。 更新
build.sbt
。"org.slf4j" % "slf4j-api" % "1.6.4",
"org.elasticsearch" % "elasticsearch" % "1.6.0",
"org.elasticsearch.test" % "framework" % "5.0.0" % "test",
"org.apache.lucene" % "lucene-test-framework" % "4.10.4" % "test",
"com.carrotsearch.randomizedtesting" % "randomizedtesting-runner" % "1.6.0" % "test",
"org.apache.lucene" % "lucene-codecs" % "4.10.4" % "test",
"org.apache.logging.log4j" % "log4j-core" % "2.8.2",
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.8.2" ,
"org.apache.lucene" % "lucene-expressions" % "4.10.4",