solor启动和xpath相关抛异常的解决
上线一个基于solr的基于rest的搜索应用服务的过程中,启动tomcat,后台抛出了两个异常
?
第一个异常
?
java.lang.RuntimeException: java.lang.ExceptionInInitializerErrorat com.taobao.terminator.manage.common.IndexBuilder.initialize(IndexBuilder.java:111)at com.taobao.terminator.manage.common.IndexBuilder.(IndexBuilder.java:59)at com.taobao.terminator.pubhook.servlet.BuildIndexAction$1.run(BuildIndexAction.java:170)at java.lang.Thread.run(Thread.java:636)Caused by: java.lang.ExceptionInInitializerErrorat com.taobao.terminator.manage.common.IndexBuilder.initialize(IndexBuilder.java:94)... 3 moreCaused by: java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/domat javax.xml.xpath.XPathFactory.newInstance(Unknown Source)at org.apache.solr.core.Config.(Config.java:42)... 4 more?
这个问题以前没有碰见过,并且在自己本地PC机上测试是不会抛出以上异常的,但是,在线上服务上就会抛出这样的异常。解决这个问题的办法是先在google上找果然找到答案,在apache solr的官方网站上找到了,http://wiki.apache.org/solr/SolrTomcat
?
Troubleshooting ErrorsIt's possible that you get an error related to the following:
?
SEVERE: Exception starting filter SolrRequestFilterjava.lang.NoClassDefFoundError: Could not initialize class org.apache.solr.core.SolrConfig at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:76).........Caused by: java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom at javax.xml.xpath.XPathFactory.newInstance(Unknown Source)
This is due to your tomcat instance not having the xalan jar file in the classpath. It took me some digging to find this, and thought it might be useful for others. The location varies from distribution to distribution, but I essentially just added (via a symlink) the jar file to the shared/lib directory under the tomcat directory.?
?
作者的解释是没有在%TOMCAT_HOME%shared/lib 这个文件夹中放xalan 相关的jar包,但是,按照作者的办法,我将xalan.jar从本地拷贝到服务上,重新启动还是不解决问题。
?
之后又对本地应用程序进行调试跟踪启动代码,最后定位到了
?
javax.xml.xpath.XPathFactoryFinder ?这个类的主要职责就就是为XPathFactory工厂类的工厂方法,通过参数找XPath的解析对象。
?
XPathFactoryFinder类中找解析对象的流程是这样的:
?
?