使用Spring Boot的ElasticsearchIntegrationTest

时间:2015-05-05 10:43:09

标签: spring elasticsearch lucene spring-boot integration

我正在尝试在Spring Boot应用程序中使用ElasticsearchIntegrationTest(http://www.elastic.co/guide/en/elasticsearch/reference/1.x/integration-tests.html)进行集成测试。

@ElasticsearchIntegrationTest.ClusterScope(scope =ElasticsearchIntegrationTest.Scope.SUITE)
public class MyElasticsearchIntegrationTests extends ElasticsearchIntegrationTest

当我运行此测试时,我收到以下错误:

java.lang.AssertionError: Version must be upgraded to [4.10.4] is still set to     [4.10.3]
at org.elasticsearch.Version.<clinit>(Version.java:229)
at org.elasticsearch.test.ElasticsearchTestCase.<clinit>(ElasticsearchTestCase.java:87)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.carrotsearch.randomizedtesting.RandomizedRunner$1.run(RandomizedRunner.java:553)

我的pom.xml中的依赖关系定义如下:

<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>1.5.1</version>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-test-framework</artifactId>
        <version>4.10.4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-elasticsearch</artifactId>
        <version>1.3.0.BUILD-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
</dependencies>

当我运行mvn dependecy:tree

[INFO] Scanning for projects...
[INFO]                                                                     
[INFO] ------------------------------------------------------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ demo ---
[INFO] com.sebpc:demo:jar:0.0.1-SNAPSHOT
[INFO] +- org.elasticsearch:elasticsearch:test-jar:tests:1.5.1:test
[INFO] |  +- org.apache.lucene:lucene-core:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-common:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-queries:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-memory:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-highlighter:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-queryparser:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-sandbox:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-suggest:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-misc:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-join:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-grouping:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-spatial:jar:4.10.4:compile
[INFO] |  |  \- com.spatial4j:spatial4j:jar:0.4.1:compile
[INFO] |  +- org.antlr:antlr-runtime:jar:3.5:compile
[INFO] |  +- org.ow2.asm:asm:jar:4.1:compile
[INFO] |  \- org.ow2.asm:asm-commons:jar:4.1:compile
[INFO] +- org.apache.lucene:lucene-test-framework:jar:4.10.4:compile
[INFO] |  +- org.apache.lucene:lucene-codecs:jar:4.10.4:compile
[INFO] |  +- com.carrotsearch.randomizedtesting:junit4-ant:jar:2.1.6:compile
[INFO] |  +- com.carrotsearch.randomizedtesting:randomizedtesting-    runner:jar:2.1.6:compile
[INFO] |  +- junit:junit:jar:4.12:compile
[INFO] |  \- org.apache.ant:ant:jar:1.8.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-elasticsearch:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |  \- org.springframework.boot:spring-boot-starter:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |     +- org.springframework.boot:spring-boot:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |     +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |     +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |     |  +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |     |  |  \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] |     |  +- org.slf4j:jul-to-slf4j:jar:1.7.11:compile
[INFO] |     |  \- org.slf4j:log4j-over-slf4j:jar:1.7.11:compile
[INFO] |     \- org.yaml:snakeyaml:jar:1.14:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.21:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.21:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.21:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.21:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |  |  \- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |     +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |     +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  |     \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.5.1:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.5.1:compile
[INFO] |  +- org.springframework:spring-web:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.3.0.BUILD-SNAPSHOT:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.springframework:spring-core:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] |  \- org.springframework:spring-test:jar:4.2.0.BUILD-SNAPSHOT:test
[INFO] +- org.springframework.data:spring-data-elasticsearch:jar:1.3.0.BUILD-SNAPSHOT:compile
[INFO] |  +- org.springframework:spring-context:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] |  +- org.springframework:spring-tx:jar:4.2.0.BUILD-SNAPSHOT:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.10.0.RELEASE:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  +- joda-time:joda-time:jar:2.7:compile
[INFO] |  +- org.elasticsearch:elasticsearch:jar:1.4.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.5.1:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.11:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.11:compile
[INFO] \- com.google.guava:guava:jar:18.0:compile

看起来所有与lucene相关的库都是4.10.4而不是4.10.3,这就是为什么我对这个错误消息有点困惑。

任何帮助将不胜感激!

由于

1 个答案:

答案 0 :(得分:0)

除非您想使用特定版本,否则不应为elasticsearch定义artefact依赖项,因为它将由spring data elasticsearch自动添加。

使用最新的spring数据elasticsearch快照1.3.0.BUILD-SNAPSHOT你将获得elasticsearch 1.5.2,无论如何都是最新版本。

建议:从您的pom中删除elasticsearch依赖项,并使用来自spring data elasticsearch的瞬态依赖项。

如果您仍想使用特定版本,则从spring data elasticsearch中排除elasticsearch依赖项。