今天在用solr4.3和web项目结合的时候,出了一个莫名的异常就是,我无论用solrj向solr服务添加数据,总是报如下的一个异常
- 六月 18, 2013 8:33:12 下午 org.apache.solr.client.solrj.impl.HttpClientUtil createClient
- 信息: Creating new http client, config:maxConnections=128&maxConnectionsPerHost=32&followRedirects=false
- Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
- at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
- at org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:78)
- at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
- at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
- at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:520)
- at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
- at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
- at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
- at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:352)
- at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:180)
- at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:117)
- at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)
- at org.apache.solr.client.solrj.SolrServer.addBean(SolrServer.java:136)
- at org.apache.solr.client.solrj.SolrServer.addBean(SolrServer.java:125)
- at solr.impl.SolrServiceImpl.addIndex(SolrServiceImpl.java:61)
- at solr.impl.SolrServiceImpl.main(SolrServiceImpl.java:35)
六月 18, 2013 8:33:12 下午 org.apache.solr.client.solrj.impl.HttpClientUtil createClient
信息: Creating new http client, config:maxConnections=128&maxConnectionsPerHost=32&followRedirects=false
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
at org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:78)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:520)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:352)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:180)
at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:117)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)
at org.apache.solr.client.solrj.SolrServer.addBean(SolrServer.java:136)
at org.apache.solr.client.solrj.SolrServer.addBean(SolrServer.java:125)
at solr.impl.SolrServiceImpl.addIndex(SolrServiceImpl.java:61)
at solr.impl.SolrServiceImpl.main(SolrServiceImpl.java:35)
这个问题我找了半天原因,也请教了好多高手,结果都不理想,因为solr4.3的部署,它的日志模块与整体的配置已经分离了,所以如果你还是按照4.2的之前的配置去启动这个solr服务那么肯定不会成功的,需要额外在配置日志模块才可以,对于这个我在这里简单说明一下,从官网下载的solr4.3的解压包里面找到例子下面的lib/ext包将其下面的所有jar包拷贝到tomcat的lib中或者拷贝到solr的webinfo/lib都可以,最后再把例子中的log4j文件拷贝到webinfo中
言归正传,关于上面的那个错误,其实因为多放了slf4j-log4j12-1.6.6.jar包导致,如果你仔细看日志信息的话就会发现有一个信息提示,在你的项目中发现了多个slf4j-log4j12-1.6.6.jar包,另外一点在hibernate中的也有一个日志jar包slf4j-log4j12-1.5.8.jar只要放的位置不冲突即可,
- SLF4J: Class path contains multiple SLF4J bindings.
- SLF4J: Found binding in [jar:file:/F:/eclipse10tomcat/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
- SLF4J: Found binding in [jar:file:/F:/eclipse10tomcat/webapps/Search/WEB-INF/lib/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
- SLF4J: Found binding in [jar:file:/F:/eclipse10tomcat/webapps/Search/WEB-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
- SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/F:/eclipse10tomcat/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/F:/eclipse10tomcat/webapps/Search/WEB-INF/lib/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/F:/eclipse10tomcat/webapps/Search/WEB-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
这个是异常的信息,OK,然后我们需要做的就是,按照上面的移除多余的jar包,即可,因为多个jar可能记录日志信息时,日志模块,不知道需要用那个jar包,记录所以就出现了最上面的那个异常问题,当我们把多余的jar包移除后(留一个即可),再启动tomcat这时候就不会出现那行信息了,至此,用solrj向solr服务添加数据,就可以成功了!