Spring配置访问Openshift elasticsearch

时间:2014-04-30 15:10:39

标签: java spring spring-mvc elasticsearch openshift

我实现了一个包含搜索字段并使用spring调用elasticsearch服务的页面。

与弹性搜索引擎的连接是通过使用spring-elasticsearch(https://github.com/dadoonet/spring-elasticsearch)提供的spring bean完成的:

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

这很好但我想将我的引擎移动到另一台服务器,所以为了开发和测试,我使用此https://github.com/caruccio/openshift-elasticsearch在elasticnshift中使用elasticsearch创建了一个应用程序,并更改了传输的客户端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看起来很有趣,但我不知道这是否有助于解决我的问题或者值得改变!

提前致谢

1 个答案:

答案 0 :(得分:0)

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

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