解决maven工程下java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts问题

maven坐标:


		    org.apache.solr
		    solr-solrj
		    4.10.2



			org.apache.httpcomponents
			httpclient
			4.5.1




maven工程中,发现使用tomcat插件启动web工程时,控制台报如下错误:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.http.impl.conn.PoolingHttpClientConnectionManager]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/http/ssl/SSLContexts
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1086)
	... 22 more
Caused by: java.lang.NoClassDefFoundError: org/apache/http/ssl/SSLContexts
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.getSocketFactory(SSLConnectionSocketFactory.java:172)
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:109)
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:116)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
	... 24 more
Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
	... 32 more

一开始,以为自己没有加入httpclient的maven坐标,但是pom文件所依赖的paraent工程,含有该坐标,而且工程中Maven Dependencies打开里面也有该jar包,然后自己clean工程,maven update,发现各种跟工程和maven的清理都无关系,到了第二天,发现pom文件中solrJ这个坐标,觉得solrJ应该会依赖httpclientjar包,因为该jar包里面有对solr服务器发起请求的api,于是自己看了下依赖,果然solrJ会对httpclient产生依赖,但本工程在开发过程中去掉了关于solr的功能,于是把solrJ坐标注释掉,重新启动工程,发现问题解决。下面是加了solrJ坐标和不加solrJ坐标的Maven Dependencies差异。

解决maven工程下java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts问题_第1张图片


或者使用6.1.0版本的solrJ,这个版本的SolrJ依赖的是4.4.1的httpcore。与maven中httpclient的4.5.1版本不产生依赖冲突,但是这个solrJ最低支持JAVA8,低版本的java会报,这个错误“Unsupported major.minor version XXXX”。

官网上对Solr6的要求是这么说的:The minimum supported version of Java for Solr 6 (and the SolrJ client libraries) is now Java 8.。


或者httpclient使用4.3的版本,这样会兼容4.10.2的solrJ

你可能感兴趣的:(java)