首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >覆盖Spring数据弹性搜索群集节点配置

覆盖Spring数据弹性搜索群集节点配置
EN

Stack Overflow用户
提问于 2014-01-26 07:03:09
回答 1查看 2K关注 0票数 0

我使用弹性搜索来搜索我的项目活动,在这些活动中,我通过spring实用程序与后端ES集群通信。

弹簧数据弹性搜索

下面是webapp的spring存储库描述。

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
    xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

    <elasticsearch:transport-client id="client" cluster-nodes="localhost:9300" />

    <bean name="elasticsearchTemplate"
        class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
        <constructor-arg name="client" ref="client" />
    </bean>

    <elasticsearch:repositories
        base-package="com.customer.repositories" />
</beans>

在这里,我将集群节点配置指定为cluster-nodes="localhost:9300",它在本地测试中运行良好。

在生产服务器中,我们使用主机IP say (192.xx.xx.xx)建立了完整的功能集群。因此,我的问题是,我们已经在生产服务器中的/etc/project/es.yml文件中的yml文件中指定了集群主机。因此,我需要调整我的应用程序,以便从这个自定义位置获取集群配置。

由于上面由spring容器初始化的spring存储库xml,我们无法覆盖这种行为。有什么方法可以用弹簧数据弹性搜索来实现吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-15 08:11:35

最后,我解决了我的问题,并在这里分享它,以便它可能是有用的其他人。

将YML更改为属性文件(es.props)

spring存储库说明应如下所示

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>co
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
    xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch
                        http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <context:property-placeholder location="file:/etc/project/es.props" />

    <elasticsearch:transport-client id="client" cluster-nodes="${es-host}:9300""/>

    <bean name="elasticsearchTemplate"
        class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
        <constructor-arg name="client" ref="client" />
    </bean>

    <elasticsearch:repositories
        base-package="com.customer.repositories" />

</beans>

其中在PropertySourcePlaceHolder中采用了Spring 3.1+的修改机制。

因此,它将在/etc/project/es.props中查找es.host。本地测试人员可以通过使用-Des.host=定制-cluser-host启动服务器来覆盖此属性。

实际上,Mohsin(Spring弹性搜索开发人员)给出了实现该解决方案的一些提示。谢谢莫辛。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21360696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档