在Quarkus中返回XML响应时,“两个类具有相同的XML类型名称”

"Two classes have the same XML type name" when returning XML response in Quarkus

提问人:Politechniczny 提问时间:11/14/2023 更新时间:11/14/2023 访问量:14

问:

Quarkus版本 - 3.2.0.Final

XCF 版本 - 2.2.2(也尝试了 5.2.0)

返回XML响应的Quarkus REST资源示例:

@GET
@Produces(MediaType.APPLICATION_XML)
public MyResponse<MyEntity> serviceThatReturnsXml() {
  // return MyResponse instance
}

MyResponse 类:

@Data
@NoArgsConstructor
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "TagName")
public class MyResponse<T> {
  @XmlElement(name = "ChildTagName")
  private List<T> items;
}

调用 REST 资源时出错:

Two classes have the same XML type name "{http://www.w3.org/2005/08/addressing}EndpointReferenceType". Use @XmlType.name and @XmlType.namespace to assign different names to them.
    this problem is related to the following location:
        at jakarta.xml.ws.wsaddressing.W3CEndpointReference
    this problem is related to the following location:
        at org.apache.cxf.ws.addressing.EndpointReferenceType
        at public org.apache.cxf.ws.addressing.EndpointReferenceType org.apache.cxf.ws.addressing.ObjectFactory.createEndpointReferenceType()
        at org.apache.cxf.ws.addressing.ObjectFactory
        at protected java.util.List org.apache.cxf.ws.addressing.MetadataType.any
        at org.apache.cxf.ws.addressing.MetadataType

    at io.quarkus.jaxb.runtime.JaxbContextProducer.createJAXBContext(JaxbContextProducer.java:82)
    at io.quarkus.jaxb.runtime.JaxbContextProducer_ClientProxy.createJAXBContext(Unknown Source)
    at io.quarkus.resteasy.reactive.jaxb.runtime.JAXBContextContextResolver.getContext(JAXBContextContextResolver.java:27)
    at io.quarkus.resteasy.reactive.jaxb.runtime.JAXBContextContextResolver.getContext(JAXBContextContextResolver.java:13)
    at io.quarkus.resteasy.reactive.jaxb.runtime.serialisers.ServerJaxbMessageBodyWriter.getMarshall(ServerJaxbMessageBodyWriter.java:82)
    at io.quarkus.resteasy.reactive.jaxb.runtime.serialisers.ServerJaxbMessageBodyWriter.marshal(ServerJaxbMessageBodyWriter.java:69)
    at io.quarkus.resteasy.reactive.jaxb.runtime.serialisers.ServerJaxbMessageBodyWriter.writeResponse(ServerJaxbMessageBodyWriter.java:51)
    at org.jboss.resteasy.reactive.server.core.ServerSerialisers.invokeWriter(ServerSerialisers.java:227)
    at org.jboss.resteasy.reactive.server.core.ServerSerialisers.invokeWriter(ServerSerialisers.java:195)
    at org.jboss.resteasy.reactive.server.core.serialization.FixedEntityWriter.write(FixedEntityWriter.java:28)
    at org.jboss.resteasy.reactive.server.handlers.ResponseWriterHandler.handle(ResponseWriterHandler.java:34)
    at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:147)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:145)
    at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
    at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
    at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:833)

pom.xml依赖项

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-reactive-jaxb</artifactId>
</dependency>

<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
</dependency>

<dependency>
    <groupId>jakarta.jws</groupId>
    <artifactId>jakarta.jws-api</artifactId>
</dependency>

<dependency>
    <groupId>io.quarkiverse.cxf</groupId>
    <artifactId>quarkus-cxf</artifactId>
</dependency>

在application.yaml中尝试了以下操作,但没有效果。

quarkus:
  jaxb:
    exclude-classes: org.apache.cxf.ws.addressing.EndpointReferenceType
    validate-jaxb-context: false

试图排除第二个

quarkus:
  jaxb:
    exclude-classes: jakarta.xml.ws.wsaddressing.W3CEndpointReference
    validate-jaxb-context: false

现在返回 response,但 main 标签包含许多未使用的 xmlns 属性:

<TagName xmlns:ns2="http://java.sun.com/xml/ns/javaee" 
xmlns:ns3="http://api.nef.co.adapter.model.esb.p4.org" 
xmlns:ns4="http://www.w3.org/2006/07/ws-policy" 
xmlns:ns5="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:ns6="http://cxf.apache.org/configuration/security" 
xmlns:ns7="https://jakarta.ee/xml/ns/jakartaee" 
xmlns:ns8="http://schemas.xmlsoap.org/ws/2004/03/addressing" 
xmlns:ns9="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:ns10="http://www.w3.org/2005/08/addressing" 
xmlns:ns11="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:ns12="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ns13="http://schemas.xmlsoap.org/wsdl/http/" 
xmlns:ns14="http://base.api.nef.co.adapter.model.esb.p4.org" 
xmlns:ns15="http://esb.p4.org" 
xmlns:ns16="http://cxf.apache.org/transports/http/configuration" 
xmlns:ns17="http://cxf.apache.org/bindings/xformat"/>

无法删除 CXF 扩展,因为它在另一段代码中使用。

如何解决依赖冲突以摆脱此错误?

XML CXF 夸库斯 Resteasy

评论

0赞 ozkanpakdil 11/19/2023
这可能是一个错误,我在 github.com/apache/camel-quarkus/issues/4603 看到了类似的东西,请尝试在 github 中打开一个问题。

答: 暂无答案