【问题标题】:None of the configured nodes are available issue with spring bootspring boot 没有配置的节点可用问题
【发布时间】:2015-11-05 11:20:10
【问题描述】:

嗨,朋友们,我正在使用 elastic search 开发 spring boot 项目,我已经在本地机器上设置了弹性搜索,并且我已经在弹性搜索中安装了 Head 插件。我的弹性搜索设置正确,显示绿色标志。 我的项目中的application-dev.yml文件如下:

server:
    port: 8080

liquibase:
    context: dev

spring:
    profiles:
        active: dev
    datasource:
        dataSourceClassName: org.h2.jdbcx.JdbcDataSource
        url: jdbc:h2:mem:jhipster;DB_CLOSE_DELAY=-1
        databaseName:
        serverName:
        username:
        password:

    jpa:
        database-platform: com.aquevix.demo.domain.util.FixedH2Dialect
        database: H2
        openInView: false
        show_sql: true
        generate-ddl: false
        hibernate:
            ddl-auto: none
            naming-strategy: org.hibernate.cfg.EJB3NamingStrategy
        properties:
            hibernate.cache.use_second_level_cache: true
            hibernate.cache.use_query_cache: false
            hibernate.generate_statistics: true
            hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
    data:
        elasticsearch:
            cluster-name: elasticsearch
            cluster-nodes: localhost:9200
    messages:
        cache-seconds: 1
    thymeleaf:
        mode: XHTML
        cache: false
    activemq:
        broker-url: tcp://localhost:61616



metrics:
    jmx.enabled: true
    spark:
        enabled: false
        host: localhost
        port: 9999
    graphite:
        enabled: false
        host: localhost
        port: 2003
        prefix: TestApollo

cache:
    timeToLiveSeconds: 3600
    ehcache:
        maxBytesLocalHeap: 16M

弹性搜索服务正在我的机器上运行,但是当我尝试先保存实体时,我的代码先将实体保存在 mysql 中,然后使用 elastic search repository 在弹性搜索中保存实体,但在将实体保存到弹性时会引发错误:

Hibernate: insert into EMPLOYEE (id, rollno) values (null, ?)
[ERROR] com.aquevix.demo.aop.logging.LoggingAspect - Exception in com.aquevix.demo.web.rest.EmployeeResource.create() with cause = null
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
        at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:298) ~[elasticsearch-1.3.2.jar:na]
        at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:214) ~[elasticsearch-1.3.2.jar:na]
        at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:105) ~[elasticsearch-1.3.2.jar:na]
        at org.elasticsearch.client.support.AbstractClient.index(AbstractClient.java:94) ~[elasticsearch-1.3.2.jar:na]
        at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:331) ~[elasticsearch-1.3.2.jar:na]
        at org.elasticsearch.action.index.IndexRequestBuilder.doExecute(IndexRequestBuilder.java:313) ~[elasticsearch-1.3.2.jar:na]
        at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91) ~[elasticsearch-1.3.2.jar:na]
        at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65) ~[elasticsearch-1.3.2.jar:na]
        at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.index(ElasticsearchTemplate.java:431) ~[spring-data-elasticsearch-1.1.3.RELEASE.jar:na]
        at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.save(AbstractElasticsearchRepository.java:138) ~[spring-data-elasticsearch-1.1.3.RELEASE.jar:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]

我也使用9300 端口而不是9200,但没有任何效果。我已经尝试了所有方法,但可以找到解决方案,请帮助!

【问题讨论】:

  • 我在这里遇到了同样的问题,同样是 Elasticsearch 2.x,你应该在你的问题中指定它。

标签: elasticsearch spring-boot spring-data-elasticsearch


【解决方案1】:

我发现解决方案 ES2.0 不能正常工作,所以我重新安装 ES1.7.3 现在它在我的情况下工作。 complete details here!

【讨论】:

  • 链接中的这部分对我有帮助:Note: Do not use 9200 as port if you want to use elasticsearch with java or spring-boot beacuse 9200 port used for http protocol and 9300 use with tcp protocol only
【解决方案2】:

我和你有同样的问题,也使用 Jhipster。如前所述,一种可能的解决方案是降级您的弹性搜索实例,但如果您不想降级它,这对我有用:

  • 将 spring boot 更新到 lastet 版本 (> 1.4.0.RC1)
  • 手动配置 ElasticsearchTemplate 而不是使用自动配置。

如果您需要更多信息,请查看此帖子: http://ignaciosuay.com/how-to-connect-spring-boot-to-elasticsearch-2-x-x/

【讨论】:

    【解决方案3】:

    我遇到了这个错误,对我来说,原因是我使用了不正确的集群名称。

    解决此错误的步骤:

    1. 确保 Spring Data Elasticsearch 与您打算使用的 Elasticsearch 版本兼容。项目的 README 中有一张表对应 Spring Data Elasticsearch 版本和 Elasticsearch 版本:
      https://github.com/spring-projects/spring-data-elasticsearch#quick-start

      就我而言,我使用的是 Spring Data Elasticsearch 3.0.7。根据表格,我需要使用 Elasticsearch 5.5.0,但我发现 Spring Data Elasticsearch 3.0.7 似乎也与 Elasticsearch 5.6.x 兼容。

    2. 确保 spring.data.elasticsearch.cluster-nodes 属性指定您的 Elasticsearch 集群用于使用本机 Elasticsearch 传输协议进行通信的端口。

      默认情况下,Elasticsearch 监听两个端口,9200 和 9300。端口 9200 用于使用 RESTful API 进行通信。端口 9300 用于使用传输协议进行通信:
      https://www.elastic.co/guide/en/elasticsearch/guide/current/_talking_to_elasticsearch.html

      Spring Data Elasticsearch 使用的 Java 客户端期望使用传输协议(默认为 9300)进行通信。

    3. 确保spring.data.elasticsearch.cluster-name 属性指定了正确的集群名称。

      如果你没有专门设置这个属性,那么默认就是“elasticsearch”。

      您可以使用 RESTful API 查找 Elasticsearch 集群名称:
      curl -XGET 'http://localhost:9200/?pretty'

      此命令将打印类似以下内容:

      { “名称”:“XXXXXXX”, "cluster_name" : "some_cluster_name", "cluster_uuid" : "XXXXXXXXXXXXXXXXXXXXXX", “版本” : { “数字”:“5.6.10”, “build_hash”:“b727a60”, “build_date”:“2018-06-06T15:48:34.860Z”, “build_snapshot”:假, “lucene_version”:“6.6.1” }, “标语”:“你知道,搜索” }

      确保将spring.data.elasticsearch.cluster-name 属性的值设置为与“cluster_name”显示的字符串相同。

    【讨论】:

      【解决方案4】:

      您似乎正在使用 JHipster(如果我可以添加的话,这是一个很棒的工具集),它使用了

      org.springframework.boot:spring-boot-starter-data-elasticsearch:-> 1.3.3.发布

      这仅适用于 ElasticSearch BELOW 2.0,因此只需安装 ElasticSearch 1.7.3 并运行您的代码

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-26
        • 1970-01-01
        • 1970-01-01
        • 2023-01-02
        • 2019-12-01
        相关资源
        最近更新 更多