我正在尝试使用es 6.2.3将项目更新为spring-boot-starter-data-elastic-search 2.0.1,但这不起作用。我收到这个错误:
INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:加载的插件 [org.elasticsearch.index.reindex.ReindexPlugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:加载的插件 [org.elasticsearch.join.ParentJoinPlugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:加载的插件 [org.elasticsearch.percolator.PercolatorPlugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:加载的插件 [org.elasticsearch.script.mustache.MustachePlugin] INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:加载的插件 [org.elasticsearch.transport.Netty3Plugin]
INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:加载的插件 [org.elasticsearch.transport.Netty4Plugin]
INFO 27836 --- [ost-startStop-1] o.elasticsearch.plugins.PluginsService:没有加载模块 ERROR 27836 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter:启动Tomcat时出错 上下文。例外: org.springframework.beans.factory.BeanCreationException。信息: 创建名为'servletEndpointRegistrar'的bean时出错 类路径资源 [组织/ springframework的/启动/致动/自动配置/端点/网络/ ServletEndpointManagementContextConfiguration.class]:
我尝试添加这些修改:
[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);
提前致谢!!
答案 0 :(得分:2)
如果某人有类似我的问题,我使用ES 5.5.0和spring boot 2.0.1以及spring data 3.0.6(但我没有在pom中设置一个版本):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
我只配置了application.properties,但我没有制作ElasticSearchConfiguration文件:
> spring.data.elasticsearch.cluster-name=progilone-cluster
> spring.data.elasticsearch.cluster-nodes=localhost:9300
> spring.data.elasticsearch.repositories.enabled=true
> spring.data.elasticsearch.properties.path.home=target/elastic-embedded
> server.port=8081
最后,最大的修正是以与实体文件(uri - &gt; findbyUri)相同的方式调用存储库文件中的函数,例如:
---实体档案
@Id
@Field(type= FieldType.text, index = true)
private String uri;
@Field(type= FieldType.text)
private String label;
--- RepositoryFile
public interface ElasticConceptRepository extends
ElasticsearchRepository<ElasticConcept, String> {
public ElasticConcept findByUri(String uri);
public ElasticConcept findByLabel(String label);
- Loader文件(我调用我的操作)
@Component
public class Loader {
@Autowired
ElasticsearchOperations operations;
@Autowired
ElasticConceptRepository elasticConceptRepository;
@PostConstruct
@Transactional
public void loadAll() {
System.out.println("------------------------------RUN");
operations.putMapping(ElasticConcept.class);
System.out.println("Loading Data");
elasticConceptRepository.save(new ElasticConcept("test1", "uri1"));
System.out.printf("Loading Completed");
}
就是这样。