我正在尝试使用es 6.2.3将项目更新为spring-boot-starter-data-elastic-search 2.0.1,但这不起作用 . 我收到此错误:
INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch . plugins.PluginsService:loaded plugin [org.elasticsearch.join.ParentJoinPlugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:loaded plugin [org.elasticsearch.percolator.PercolatorPlugin] INFO 27836 - - [ost-startStop-1] o.elasticsearch.plugins.PluginsService:loaded plugin [org.elasticsearch.script.mustache.MustachePlugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:loaded plugin [org.elasticsearch.transport.Netty3Plugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:loaded plugin [org.elasticsearch.transport.Netty4Plugin] INFO 27836 --- [ost-startStop -1] o.elasticsearch.plugins.PluginsService:没有加载模块ERROR 27836 --- [ost-startStop-1] osbweb.embedded.tomcat.TomcatStarter:启动Tomcat上下文错误XT . 例外:org.springframework.beans.factory.BeanCreationException . 消息:在类路径资源[org / springframework / boot / actuate / autoconfigure / endpoint / web / ServletEndpointManagementContextConfiguration.class]中定义名称为'servletEndpointRegistrar'的bean时出错:
我尝试添加这些修改:
[1] https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready [2] https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide
但仍然无法工作,也许有人有一个很好的配置springboot数据和application.properties?
ElasticSearchConfiguration的代码:
public Client client() throws Exception{
Settings esSettings = Settings.builder()
.put("cluster.name", EsClusterName)
.build();
//https://www.elastic.co/guide/en/elasticsearch/guide/current/_transport_client_versus_node_client.html
TransportClient client= new PreBuiltTransportClient(esSettings).addTransportAddress( new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort));
return client();
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() throws Exception {
return new ElasticsearchTemplate(client());
}
application.properties:
elasticsearch.clustername = progilone-cluster
elasticsearch.host = localhost
elasticsearch.port = 9300
management.endpoints.web.base-path=/application
management.endpoints.web.path-mapping.health=healthcheck
spring.data.elasticsearch.cluster-nodes
应用:
public void run(String... strings) throws Exception {
System.out.println("------------------------------RUN");
ElasticConcept eC1=new ElasticConcept("test1","uri1");
ElasticConcept eC2=new ElasticConcept("test2","uri2");
elasticConceptRepository.save(eC1);
elasticConceptRepository.save(eC2);
Iterable<ElasticConcept> customers = elasticConceptRepository.findAll();
customers.forEach(System.out::println);
IndexQuery indexQuery = new IndexQueryBuilder().withId(eC1.getLabel()).withObject(eC1).build();
elasticsearchTemplate.index(indexQuery);
提前致谢!!
1 回答
如果某人有类似我的问题,我使用ES 5.5.0与spring boot 2.0.1和spring data 3.0.6(但我没有在pom中设置一个版本):
我只配置了application.properties,但我没有创建ElasticSearchConfiguration文件:
最后,最大的修正是以与实体文件(uri - > findbyUri)相同的方式调用存储库文件中的函数,例如:
---实体文件
--- RepositoryFile
--Loader文件(我调用我的操作)
就这样 .