当您的dns url不是ElasticSearch端口时,如何使用spring boot配置ElasticSearch
@configuration@enableelasticsearchrepositories(basepackageclasses={com.upgrad.careersapi.repository.elasticjobrepository.class})@componentscan(basepackageclasses={com.upgrad.careersapi.service.esservice.class})公共类elasticconfiguration{
@Autowired
private Environment environment;
@Bean
public RestHighLevelClient client(){
ClientConfiguration clientConfiguration =
ClientConfiguration.builder()
.connectedTo("https://elastic_url")
.withBasicAuth("username",
"password")
.build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
public ElasticsearchOperations elasticsearchTemplate(){
return new ElasticsearchRestTemplate(client());
}
}
我得到这个错误
无法分析端口号:https://elastic_url 位于org.springframework.data.elasticsearch.client.inetsocketaddressparser.parse(inetsocketaddressparser)。java:68)在org.springframework.data.elasticsearch.client.clientconfigurationbuilder.parse(clientconfigurationbuilder。java:238)在java.base/java.util.stream.referencepipeline$3$1.accept(referencepipeline。java:195)在java.base/java.util.spliterators$arrayspliterator.foreachremaining(spliterators。java:948)在java.base/java.util.stream.abstractpipeline.copyinto(abstractpipeline。java:484)在java.base/java.util.stream.abstractpipeline.wrapandcopyinto(abstractpipeline。java:474) 在java.base/java.util.stream.reduceops$reduceop.evaluatesequential(reduceops。java:913)在java.base/java.util.stream.abstractpipeline.evaluate(abstractpipeline。java:234)在java.base/java.util.stream.referencepipeline.collect(referencepipeline。java:578)在org.springframework.data.elasticsearch.client.clientconfigurationbuilder.connectedto(clientconfigurationbuilder。java:74)位于org.springframework.data.elasticsearch.client.clientconfiguration$clientconfigurationbuilderwithrequiredendpoint.connectedto(客户端配置)。java:189)在com.upgrad.careers.careersapi.config.elasticconfiguration.client(elasticconfiguration。java:28)在com.upgrad.careers.careersapi.config.elasticconfiguration$$enhancerbyspringcglib$$c0c6635d.cglib$client$0()在com.upgrad.careers.careersapi.config.elasticconfiguration$$enhancerbyspringcglib$$c0c6635d$$fastclassbyspringcglib$$90208c30.invoke()在org.springframework.cglib.proxy.methodproxy.invokesuper(methodproxy。java:244)在org.springframework.context.annotation.configurationclassenhancer$beanmethodinterceptor.intercept(configurationclassenhancer。java:331)在com.upgrad.careers.careersapi.config.elasticconfiguration$$enhancerbyspringcglib$$c0c6635d.client()上java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke0(本机方法)位于java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl)。java:62)在java.base/jdk.internal.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)在java.base/java.lang.reflect.method.invoke(method。java:566) 位于org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy)。java:154) ... 99个公共帧已从目标vm断开连接,地址:'127.0.0.1:53432',传输:'socket'
暂无答案!
目前还没有任何答案,快来回答吧!