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
现在返回了响应,但主标签包含许多未使用的 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 扩展无法删除,因为它已在另一段代码中使用。
如何解决依赖冲突来摆脱这个错误?
在我将两个类写在一个排除类中之后,它对我有用 我的 application.yaml 中的行:
quarkus:
jaxb:
exclude-classes: org.apache.cxf.ws.addressing.EndpointReferenceType,jakarta.xml.ws.wsaddressing.W3CEndpointReference