Restlet版本2.2 java.lang.无此类方法错误:javax/xml/流/XML输入工厂.新工厂()

u0sqgete  于 2023-02-28  发布在  Java
关注(0)|答案(2)|浏览(104)

我正在使用带有IBM jdk 1.6.0_26的Restlet Version 2.2.0,并尝试实现REST服务。在执行测试项目时,我收到以下错误:

Starting the internal [HTTP/1.1] server on port 8080
Server started ...
An exception occured writing the response entity

java.lang.NoSuchMethodError: javax/xml/stream/XMLInputFactory.newFactory()Ljavax/xml/stream/XMLInputFactory;
    at org.restlet.ext.jackson.JacksonRepresentation.createObjectMapper(JacksonRepresentation.java:215)
    at org.restlet.ext.jackson.JacksonRepresentation.getObjectMapper(JacksonRepresentation.java:333)
    at org.restlet.ext.jackson.JacksonRepresentation.createObjectWriter(JacksonRepresentation.java:277)
    at org.restlet.ext.jackson.JacksonRepresentation.getObjectWriter(JacksonRepresentation.java:361)
    at org.restlet.ext.jackson.JacksonRepresentation.write(JacksonRepresentation.java:474)
    at org.restlet.engine.adapter.ServerCall.writeResponseBody(ServerCall.java:519)
    at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:463)
    at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:196)
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
    at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:73)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:77)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:567)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:539)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:737)
Unable to send error response

java.io.IOException: headers already sent
    at sun.net.httpserver.ExchangeImpl.sendResponseHeaders(ExchangeImpl.java:180)
    at sun.net.httpserver.HttpExchangeImpl.sendResponseHeaders(HttpExchangeImpl.java:80)
    at org.restlet.engine.connector.HttpExchangeCall.writeResponseHead(HttpExchangeCall.java:157)
    at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:459)
    at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:214)
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
    at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:73)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:77)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:567)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:539)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:737)

在使用Sun/Oracle 1.6 JDK时,这个问题不存在,但我需要继续使用IBM jdk 1.6.0_26。
任何帮助都将不胜感激。
谢谢你,EHa

rt4zxlrg

rt4zxlrg1#

这可能是两个JDK之间的回退JAXP选择出现问题。请使用-Djaxp.debug=1运行java,然后查看日志。我目前遇到了相同的问题,我的日志显示

JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using ClassLoader: null

我很确定我的问题与OSGi有关。下面是另一个问题的链接,可能会有类似的结果:Unable to find a factory for http://www.w3.org/2001/XMLSchema

lrpiutwd

lrpiutwd2#

我遇到了完全相同的错误,但在不同的上下文中。错误源于以下内容:

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
...
...
    private static XmlMapper xmlMapper=null;
...
...
    xmlMapper = new XmlMapper();

从这里的评论中,我想到了将jackson-dataformat-xml的版本从2.14.2更改为2.12.7,并且成功了。

相关问题