spring集成elasticSearch es spring-boot-starter-data-elasticsearch 权限 密码配置

本文详细介绍了如何在Spring Boot项目中集成Elasticsearch,包括引入依赖、配置不同版本的连接方式,以及如何处理带密码认证的配置。还提到如何避免健康检查错误,并展示了不同版本的配置方法变迁。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文讲述使用spring集成elasticSearch

1、引入spring-boot-starter-data-elasticsearch包
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
2、添加es配置

不同的版本的配置方法不太一致。这里我呈现两个版本的配置方式

image-20211216155039753

4.30版本

方法一、yml文件添加

spring:
  elasticsearch:
    uris: ["127.0.0.1:9200"]
    username: "elastic"
    password: "yuyuyu"
    

方法二、便携config文件

package com.example.esdemo;

import lombok.extern.log4j.Log4j2;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值