【问题标题】:Spring configuration to access Openshift elasticsearchSpring配置访问Openshift elasticsearch
【发布时间】:2014-04-30 15:10:38
【问题描述】:

我正在实现一个页面,该页面有一个搜索字段并使用 spring 调用弹性搜索服务。

使用 spring-elasticsearch (https://github.com/dadoonet/spring-elasticsearch) 提供的 spring bean 完成与 elasticsearch 引擎的连接:

  <elasticsearch:client id="esClient" esNodes="localhost:9300" />

这工作得很好,但我想将我的引擎移动到不同的服务器,所以为了开发和测试,我使用这个 https://github.com/caruccio/openshift-elasticsearch 在 Openshift 中使用弹性搜索创建了一个应用程序,并更改了传输的客户端 esNode 链接。这里的问题总是给我这样的错误(或类似的错误):

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.projectx.standard.services.common.SearchEngineService com.projectx.standard.app.controler.common.IndexController.searchEngineService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchEngineService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.elasticsearch.client.Client com.projectx.standard.services.common.implementation.ElasticSearchServiceImpl.esClient; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'esClient': Invocation of init method failed; nested exception is java.lang.NumberFormatException: For input string: "//elastic-projectxserver.rhcloud.com/"
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

我认为问题出在链接中,因为我在 esNodes 字段中使用了 http://...,但我不确定。

有人知道如何把应用程序连接到openshift中的引擎吗?

顺便说一句,我发现这个 https://github.com/spring-projects/spring-data-elasticsearch 看起来很有趣,但我不知道这是否有助于解决我的问题或值得改变!

提前致谢

【问题讨论】:

    标签: java spring spring-mvc elasticsearch openshift


    【解决方案1】:

    这将不起作用,因为https://github.com/dadoonet/spring-elasticsearch 代码需要host:port 形式的配置。查看异常,您提供的主机为http://elastic-projectxserver.rhcloud.com/。该库将按: 拆分它,您将//elastic-projectxserver.rhcloud.com/ 作为端口。这就是你得到 NumberFormatException 的原因,因为端口应该是一个 int。在您的客户端配置中,尝试使用elastic-projectxserver.rhcloud.com:80

    另外,我建议你使用https://github.com/spring-projects/spring-data-elasticsearch,因为那是官方的 Spring ElasticSearch 库。

    【讨论】:

    • 感谢您的推荐。我已经更改了库的代码!关于这个问题,我尝试使用 elastic-projectxserver.rhcloud.com:80 但给了我另一个 erro:org.elasticsearch.client.transport.NoNodeAvailableException: No node available 我猜链接错误或端口错误。我也尝试使用 9300 端口,但同样发生了!
    猜你喜欢
    • 1970-01-01
    • 2017-08-13
    • 2015-12-26
    • 2019-02-23
    • 2019-11-08
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    相关资源
    最近更新 更多