如何"Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.common.logging.Loggers"?

How to "Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.common.logging.Loggers"?

所以,我正在尝试集成 Elasticsearch,但是我的 Spring 启动应用程序无法正常启动

我的pom.xml文件

<properties>
    <elasticsearch.version>6.8.0</elasticsearch.version>
</properties>

<dependencies>
    ....
    <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-spring</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>6.5.4</version>
    </dependency>
    ....
</dependencies>

和配置Bean:

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.contacts.demo.elasticsearch")
public class ElasticSearchConfiguration {

    @Bean
    public Client client() throws UnknownHostException {
        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", true).build();
        TransportClient transportClient = new PreBuiltTransportClient(settings);
        transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
        return transportClient;
    }
}

有了这个我得到

不存在以下方法:

org.elasticsearch.common.logging.Loggers.getLogger(Ljava/lang/Class;)Lorg/apache/logging/log4j/Logger;

方法的 class、org.elasticsearch.common.logging.Loggers 可从以下位置获得:

jar:file:/home/user/.m2/repository/org/elasticsearch/elasticsearch/6.8.0/elasticsearch-6.8.0.jar!/org/elasticsearch/common/logging/Loggers.class

它是从以下位置加载的:

file:/home/user/.m2/repository/org/elasticsearch/elasticsearch/6.8.0/elasticsearch-6.8.0.jar

操作:

更正应用程序的 class 路径,使其包含 org.elasticsearch.common.logging.Loggers

的单一兼容版本

我看过一些相同的主题,但是 elasticsearch.version 属性 对我没有帮助

您已将 org.elasticsearch.client:transport 的版本覆盖为 6.5.4,而您似乎正在使用 Elasticsearch 的所有其他模块的 6.8.0org.elasticsearch.client:transport 包含在 Spring Boot 的 Elasticsearch 依赖管理中,因此我建议从您的 pom 中删除 <version> 并改用托管版本:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
</dependency>