Saxon 交付 V1 Xpath 对象

Saxon delivering a V1 Xpath object

我已经成功使用 SAXON HE 9.5.1-5 一段时间了。 我们正在对我们平台中的某些组件版本进行全面升级,其中包括迁移到 Saxon 9.8.0-8 代码使用该版本失败。 以下是我们的 Spring beans 文件:

    <bean id="xpathFactory" class="net.sf.saxon.xpath.XPathFactoryImpl" factory-method="newInstance"/>
    <bean id="xpath" factory-bean="xpathFactory" factory-method="newXPath"/>
    <bean id="myRequestValidator" class="gov.dhs.ice.prime.query.RequestValidator">
            <constructor-arg index="0" ref="xpath"/>

如您所见,最后一个 bean 传递了 "newXPath" 方法的结果。 对于调试,我得到传入对象的名称。 使用9.5.1-5时,传入的对象是net.sf.saxon.xpath.XPathEvaluator对象 现在使用 9.8.0-8,我收到一个 org.apache.xpath.jaxp.XPathImpl 对象

RequestValidator 程序然后作为构造函数的一部分进行一些 XPath 编译。使用 XPathEvaluator 对象,一切都很好(一直以来都是如此) 现在我得到一个 org.apache.xpath.jaxp.XPathImpl 对象,当程序试图编译 V2 XPath 语句时构造函数失败。 V1 工作正常。
那么,为什么这个新版本返回的对象与以前不同?

我试过直接构建 net.sf.saxon.xpath.XPathEvaluator..

    <bean id="xpath" class="net.sf.saxon.xpath.XPathEvaluator"/>
    <bean id="myRequestValidator" class="gov.dhs.ice.prime.query.RequestValidator">
            <constructor-arg index="0" ref="xpath"/>

这适用于新版本。但是,文档似乎推荐了较早的方法。

知道这是怎么回事吗? 谢谢

某些版本的 Saxon 不再将自己注册为 JAXP XPathFactory,请参阅 http://saxonica.com/html/documentation9.8/xpath-api/jaxp-xpath/factory.html:

The JAXP API is designed on the basis that when your application invokes XPathFactory.newInstance(), an XPath engine is selected by examining the values of system properties and searching the classpath. If you rely on this mechanism, then your application may end up running with an XPath engine on which it has never been tested. Since different XPath engines can differ in many significant respects (most notably, the version of XPath that they support), this can easily lead to application failures. Saxon therefore no longer identifies itself (in the JAR file manifest) as a JAXP XPath supplier. If you want to load Saxon as your XPath engine, you need to select it explicitly; it's not enough to just put it on the classpath

而你认为调用net.sf.saxon.xpath.XPathFactoryImplnewInstance方法实际上是基class的抽象基classhttps://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance-- and that is calling the other overload https://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance-java.lang.String-的方法] 应该加载 JAXP 注册的 XPathFactory。

所以你应该做的是:"If you want to use Saxon as your XPath implementation, you must instantiate the class net.sf.saxon.xpath.XPathFactoryImpl directly.",例如在 Java 代码中 new net.sf.saxon.xpath.XPathFactoryImpl().

我不确定在那个 bean 语法声明方式中是如何表达的,但也许你知道或者其他人可以帮助解决这个问题。