当前位置: 首页 > 知识库问答 >
问题:

如何“更正应用程序的类路径,使其包含一个兼容版本的org.elasticsearch.common.logging.Loggers”?

凌永逸
2023-03-14

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

我的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;

该方法的类org.elasticsearch.common.logging.Logger可从以下位置获得:

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

措施:

更正应用程序的类路径,使其包含一个兼容版本的org.elasticsearch.common.logging.记录器

我见过一些相同的话题,但elasticsearch.version财产对我没有帮助

共有1个答案

凌长恨
2023-03-14

您已经覆盖了org的版本。elasticsearch。客户端:当您似乎正在使用Elasticsearch的所有其他模块时,将其传输为6.5.4<代码>组织。elasticsearch。客户端:Spring Boot的Elasticsearch依赖项管理中包含传输,因此我建议删除

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
</dependency>
 类似资料: