ElasticSearch版本与Jar包冲突

本人之前在本地搭建了es2.4,然后使用spring-data-es创建elasticSearchTemplate进行crud操作。

这些完全没问题,然而一切问题在我连接公司的es之后就爆发了。

问题1:spring-data-es不支持5.*版本,所以自然会报错。

问题2:即便你不用spring-data-es,也会报错。因为spring-data-es 的maven文件必须要删除掉,对应的xml文件中的配置代码也要删掉。

Exception
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchFieldError: defaultConnectionProfile
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:978)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)


Root Cause
java.lang.NoSuchFieldError: defaultConnectionProfile
	org.elasticsearch.transport.netty4.Netty4Transport.createBootstrap(Netty4Transport.java:197)
	org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:162)
	org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69)
	org.elasticsearch.transport.TransportService.doStart(TransportService.java:188)
	org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69)
	org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:187)
	org.elasticsearch.client.transport.TransportClient.(TransportClient.java:247)
	org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:125)
	org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:111)
	org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:101)
	com.cmcc.utils.ESUtils.getTransPortClient(ESUtils.java:31)
	com.cmcc.controller.ES5Controller.save(ES5Controller.java:42)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

解决办法,注释掉,下面的依赖


    org.springframework.data
    spring-data-elasticsearch
    3.0.8.RELEASE

你所需要的依赖只有(服务器中的es版本也是5.1.2,要保持一致)

		
		    org.elasticsearch
		    elasticsearch
		    5.1.2
		
		
		
	
        
		    org.elasticsearch.client
		    transport
		    5.1.2
		
        	

 

你可能感兴趣的:(es,错误,es)