Spring 连接验证带账号密码的elaticsearch集群

        最近刚好一个项目,由于其他原因,需要将elaticsearch集群加上账号密码访问(之前一直都是直接访问elaticsearch,未加账号密码,所用到的elaticsearch版本号2.4.0)。

    maven依赖

<dependency>
   <groupId>org.elasticsearch.plugin</groupId>
   <artifactId>shield</artifactId>
   <version>2.4.0</version>
</dependency>
elasticsearch.properties配置文件
#es集群名称
es.cluster.name=flowaudit
es.client.transport.sniff=false

#es服务器ip以及tcp端口
#es.transport.address.list=127.0.0.1:9301
#es 账号密码
es.shield.user=root:surfilter@1218
#es tcp端口
es.transport.port=9301

#es 索引名称
es.index.name=app
es.index.type=appinfo

applicationContext-es.xml配置文件

<?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: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.xsd
          http://www.springframework.org/schema/context  
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <description>elasticsearch索引配置</description>
     <!--配置esManager的名称以及路径-->
    <bean id="esManager" class="com.surfilter.pscms.app.market.manager.ESManager">
        <constructor-arg ref="esClient"/>
    </bean>
</beans>

配置好以后,在其他地方之间采用spring的自动注入方法(如下),即可正常操作elaticsearch

@Autowired
private ESManager esManager;

esManager代码文件以及其他相关代码文件参考附件下载

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值