Spring mvc 覆盖Spring数据弹性搜索群集节点配置
我正在使用弹性搜索来搜索我的项目活动,其中我通过spring实用程序与后端ES集群通信 spring数据弹性搜索 以下是webapp的spring存储库描述Spring mvc 覆盖Spring数据弹性搜索群集节点配置,spring-mvc,jpa,
elasticsearch,spring-data,Spring Mvc,Jpa,
elasticsearch,Spring Data,我正在使用弹性搜索来搜索我的项目活动,其中我通过spring实用程序与后端ES集群通信 spring数据弹性搜索 以下是webapp的spring存储库描述 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xm
<?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(192.xx.xx.xx)进行了全功能集群设置。因此,我的问题是,我们在生产服务器的/etc/project/es.yml文件中的yml文件中指定了集群主机。因此,我需要调整我的应用程序,从这个自定义位置获取集群配置
由于上面的spring存储库xml是由spring容器初始化的,因此我们无法覆盖该行为。有没有办法用spring data elastic search实现它?最后我解决了我的问题,并在这里分享了它,这样它可能对其他人有用 将YML idea更改为属性文件(es.props) spring存储库描述如下
<?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>
co
嘿,spring数据或弹性搜索专家,这个问题有什么解决方案吗?spring伙计们有什么意见吗?