XMLStreamException:名称空间 URI 尚未绑定到前缀,IBM jre

XMLStreamException: The namespace URI has not been bound to a prefix,IBM jre

我的项目在 tomcat 服务器上运行良好,现在我正尝试 运行 在 WebSphere Liberty Profile(WLP) 上进行项目,但它给我以下 stax 实现错误

     javax.xml.stream.XMLStreamException: The namespace URI "http://www.example.com/ns1" has not bound to a prefix.
  at  com.ibm.xml.xlxp.api.stax.msg.StAXMessageProvider.throwXMLStreamException(StAXMessageProvider.java:59)
  at com.ibm.xml.xlxp.api.stax.XMLStreamWriterBase.writeAttribute(XMLStreamWriterBase.java:464)
  at com.ibm.xml.xlxp.api.stax.XMLOutputFactoryImpl$XMLStreamWriterProxy.writeAttribute(XMLOutputFactoryImpl.java:157)
  at org.apache.olingo.odata2.core.ep.producer.XmlMetadataProducer.writeAnnotationAttributes(XmlMetadataProducer.java:599)
  at org.apache.olingo.odata2.core.ep.producer.XmlMetadataProducer.writeMetadata(XmlMetadataProducer.java:134)

我已经在 WLP 中将类加载器策略设置为父级最后。 如何在IBM jre中实现stax

IBM JRE 确实包含 STAX,它是 Java SE 的一部分。

JavawriteAttribute 的文档表明,如果您正在编写一个带有尚未绑定到前缀的名称空间的属性,则预计会出现此异常。如果没有关于您打算编写的文档的更多信息,我无法确认是否属于这种情况。

如果是这种情况,您需要修复您正在编写的文档,以便它在您使用命名空间之前为命名空间设置前缀,或者设置 javax.xml.stream.isRepairingNamespaces 属性 在创建 XMLStreamWriter 之前将输出工厂 true

按照 Java文档中的示例:

xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));

我不知道为什么这对 tomcat 有效,但对 liberty 无效。 Knowledge Center.

中提供了有关 IBM STAX 实施的更多信息

问题已解决,感谢您的回复。 这是 solution:I 已将 stax2-api 和 woodstox-core-asl jar 添加到我的项目中,并在我的项目 属性 下方设置 system.properties

javax.xml.stream.XMLOutputFactory=com.ctc.wstx.stax.WstxOutputFactory
javax.xml.stream.XMLInputFactory=com.ctc.wstx.stax.WstxInputFactory