java.lang.ClassNotFoundException:com.sun.xml.internal.bind.v2.ContextFactory

use*_*872 3 java spring spring-boot spring-webflux spring-webclient

\n

春季启动版本2.4.4

\n

Java版本15

\n
\n
@Bean\n    public WebClient webClient() {\n        return WebClient.builder().baseUrl(BASE_URL)\n                .defaultHeaders(header -> header.setBasicAuth("test",\n                        "testpwd"))\n                .clientConnector(new ReactorClientHttpConnector(HttpClient.newConnection()))\n                .exchangeStrategies(ExchangeStrategies.builder().codecs(configurer -> {\n                    configurer.defaultCodecs().jaxb2Encoder(new Jaxb2XmlEncoder());\n                    configurer.defaultCodecs().jaxb2Decoder(new Jaxb2XmlDecoder());\n                }).build()).build();\n        \n    }\n
Run Code Online (Sandbox Code Playgroud)\n

使用 Spring boot 2.4.4 webclient 并尝试使用 XML 响应来使用服务。

\n
public Mono<ServerResponse> retrieveServices() {\n\n        // Headers can be passed here or while building the client\n        Mono<DirectoryOfService> serviceMono = webClient\n             .get().uri("/api/v1/test/services")\n            .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE)\n            .accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)\n            .retrieve().bodyToMono(DirectoryOfService.class);\n\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

错误:-

\n
    org.springframework.core.codec.CodecException: Could not create JAXBContext for class [class com.test.model.DirectoryOfService]: Implementation of JAXB-API has not been found on module path or classpath.; nested exception is javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.\n - with linked exception:\n[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]\n    at org.springframework.http.codec.xml.JaxbContextContainer.lambda$getJaxbContext$0(JaxbContextContainer.java:58) ~[spring-web-5.3.5.jar:5.3.5]\n    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: \nError has been observed at the following site(s):\n    |_ checkpoint \xe2\x87\xa2 Body from GET https://test.com/api/v1/services [DefaultClientResponse]\n    |_ checkpoint \xe2\x87\xa2 HTTP GET "/api/v1/services" [ExceptionHandlingWebHandler]\nStack trace:\n        at org.springframework.http.codec.xml.JaxbContextContainer.lambda$getJaxbContext$0(JaxbContextContainer.java:58) ~[spring-web-5.3.5.jar:5.3.5]\n        at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]\n        at org.springframework.http.codec.xml.JaxbContextContainer.getJaxbContext(JaxbContextContainer.java:52) ~[spring-web-5.3.5.jar:5.3.5]\n        at org.springframework.http.codec.xml.JaxbContextContainer.createUnmarshaller(JaxbContextContainer.java:47) ~[spring-web-5.3.5.jar:5.3.5]\n        at org.springframework.http.codec.xml.Jaxb2XmlDecoder.initUnmarshaller(Jaxb2XmlDecoder.java:235) ~[spring-web-5.3.5.jar:5.3.5]\n        at org.springframework.http.codec.xml.Jaxb2XmlDecoder.unmarshal(Jaxb2XmlDecoder.java:216) ~[spring-web-5.3.5.jar:5.3.5]\n        at org.springframework.http.codec.xml.Jaxb2XmlDecoder.decode(Jaxb2XmlDecoder.java:195) ~[spring-web-5.3.5.jar:5.3.5]\n        at org.springframework.http.codec.xml.Jaxb2XmlDecoder.lambda$decodeToMono$2(Jaxb2XmlDecoder.java:183) ~[spring-web-5.3.5.jar:5.3.5]\n        at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.FluxMapFuseable$MapFuseableConditionalSubscriber.onNext(FluxMapFuseable.java:295) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.FluxFilterFuseable$FilterFuseableConditionalSubscriber.onNext(FluxFilterFuseable.java:337) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1815) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.MonoCollect$CollectSubscriber.onComplete(MonoCollect.java:159) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:142) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:259) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:142) ~[reactor-core-3.4.4.jar:3.4.4]\n        at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:401) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n        at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:416) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n        at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:470) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n        at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:685) ~[reactor-netty-http-1.0.5.jar:1.0.5]\n        at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:94) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) ~[netty-codec-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) ~[netty-codec-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1534) ~[netty-handler-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1283) ~[netty-handler-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1330) ~[netty-handler-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508) ~[netty-codec-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447) ~[netty-codec-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) ~[netty-codec-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.60.Final.jar:4.1.60.Final]\n        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.60.Final.jar:4.1.60.Final]\n        at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]\nCaused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.\n    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278) ~[jaxb-api-2.3.1.jar:2.3.0]\n    at javax.xml.bind.ContextFinder.find(ContextFinder.java:421) ~[jaxb-api-2.3.1.jar:2.3.0]\n    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) ~[jaxb-api-2.3.1.jar:2.3.0]\n    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662) ~[jaxb-api-2.3.1.jar:2.3.0]\n    at org.springframework.http.codec.xml.JaxbContextContainer.lambda$getJaxbContext$0(JaxbContextContainer.java:54) ~[spring-web-5.3.5.jar:5.3.5]\n    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]\n    at org.springframework.http.codec.xml.JaxbContextContainer.getJaxbContext(JaxbContextContainer.java:52) ~[spring-web-5.3.5.jar:5.3.5]\n    at org.springframework.http.codec.xml.JaxbContextContainer.createUnmarshaller(JaxbContextContainer.java:47) ~[spring-web-5.3.5.jar:5.3.5]\n    at org.springframework.http.codec.xml.Jaxb2XmlDecoder.initUnmarshaller(Jaxb2XmlDecoder.java:235) ~[spring-web-5.3.5.jar:5.3.5]\n    at org.springframework.http.codec.xml.Jaxb2XmlDecoder.unmarshal(Jaxb2XmlDecoder.java:216) ~[spring-web-5.3.5.jar:5.3.5]\n    at org.springframework.http.codec.xml.Jaxb2XmlDecoder.decode(Jaxb2XmlDecoder.java:195) ~[spring-web-5.3.5.jar:5.3.5]\n    at org.springframework.http.codec.xml.Jaxb2XmlDecoder.lambda$decodeToMono$2(Jaxb2XmlDecoder.java:183) ~[spring-web-5.3.5.jar:5.3.5]\n    at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.FluxMapFuseable$MapFuseableConditionalSubscriber.onNext(FluxMapFuseable.java:295) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.FluxFilterFuseable$FilterFuseableConditionalSubscriber.onNext(FluxFilterFuseable.java:337) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1815) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.MonoCollect$CollectSubscriber.onComplete(MonoCollect.java:159) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:142) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:259) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:142) ~[reactor-core-3.4.4.jar:3.4.4]\n    at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:401) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n    at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:416) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n    at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:470) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n    at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:685) ~[reactor-netty-http-1.0.5.jar:1.0.5]\n    at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:94) ~[reactor-netty-core-1.0.5.jar:1.0.5]\n    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) ~[netty-codec-4.1.60.Final.jar:4.1.60.Final]\n    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) ~[netty-codec-4.1.60.Final.jar:4.1.60.Final]\n    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.60.Final.jar:4.1.60.Final]\n
Run Code Online (Sandbox Code Playgroud)\n

构建.gradle,

\n
dependencies {\n    implementation 'org.springframework.boot:spring-boot-starter-webflux'\n    implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '3.0.0'\n    implementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '3.0.0'\n    implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'\n        \n}\n
Run Code Online (Sandbox Code Playgroud)\n

删除 com.sun.xml.bind 并添加 glassfish 后,出现以下错误。

\n
\n

实现 'org.glassfish.jaxb:jaxb-runtime:2.3.1'

\n
\n

错误 :

\n
org.springframework.core.codec.CodecException: Could not create JAXBContext for class [class com.test.model.DirectoryOfService]: 10 counts of IllegalAnnotationExceptions; nested exception is com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 10 counts of IllegalAnnotationExceptions\nClass has two properties of the same name "section"\n    this problem is related to the following location:\n        at public com.test.model.Section com.test.model.DirectoryOfService.getSection()\n        at com.test.model.DirectoryOfService\n    this problem is related to the following location:\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\nClass has two properties of the same name "name"\n    this problem is related to the following location:\n        at public java.lang.String com.test.model.Section.getName()\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\n    this problem is related to the following location:\n        at private java.lang.String com.test.model.Section.name\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\nClass has two properties of the same name "test"\n    this problem is related to the following location:\n        at public java.util.List com.test.model.Section.getTest()\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\n    this problem is related to the following location:\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\nClass has two properties of the same name "code"\n    this problem is related to the following location:\n        at public java.lang.String com.test.model.Test.getCode()\n        at com.test.model.Test\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\n    this problem is related to the following location:\n        at private java.lang.String com.test.model.Test.code\n        at com.test.model.Test\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\nClass has two properties of the same name "currency"\n    this problem is related to the following location:\n        at public java.lang.String com.test.model.Test.getCurrency()\n        at com.test.model.Test\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\n    this problem is related to the following location:\n        at private java.lang.String com.test.model.Test.currency\n        at com.test.model.Test\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\nClass has two properties of the same name "includes"\n    this problem is related to the following location:\n        at public java.lang.String com.test.model.Test.getIncludes()\n        at com.test.model.Test\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\n    this problem is related to the following location:\n        at private java.lang.String com.test.model.Test.includes\n        at com.test.model.Test\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\nClass has two properties of the same name "name"\n    this problem is related to the following location:\n        at public java.lang.String com.test.model.Test.getName()\n        at com.test.model.Test\n        at private java.util.List com.test.model.Section.test\n        at com.test.model.Section\n        at private com.test.model.Section com.test.model.DirectoryOfService.section\n        at com.test.model.DirectoryOfService\n    this problem is related to the following location:\n        at private java.lang

jcc*_*ero 9

尽管您测试了类似的方法,但请考虑查看此 Github 问题,尤其是最后一条评论,我认为它会有所帮助。

确保还拥有适当版本的 JAXB 运行时。在您之前的问题中,Spring 似乎无法在您的类路径中找到合适的 JAXB 实现。jaxb-api对于您在依赖项中指定的版本2.3.1,请删除与以下项相关的依赖项com.sun.xml.bind并包含以下项:

implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
Run Code Online (Sandbox Code Playgroud)

org.glassfish.jaxb jaxb-runtime例如,最近的版本3.0.0取决于 ,org.glassfish.jaxb jaxb-core而 又取决于jakarta.xml.bind jakarta.xml.bind-api,基于 Eclipse Foundation 的 Java EE JAXB 实现。如果您想使用org.glassfish.jaxb:jaxb-runtime:3.0.0包含以下依赖项:

implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '3.0.0'
Run Code Online (Sandbox Code Playgroud)

而不是您之前定义的 JAXB API:

implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
Run Code Online (Sandbox Code Playgroud)

请更改您的导入结果并仔细测试它,我从未使用 SpringWebClient和相关的 JAXB 编解码器测试过它。

关于重复的问题section,JAXB 似乎正在尝试序列化 POJO 的字段和方法定义属性。为了避免该问题,请使用注释显式定义访问类型@XmlAccessorType。例如:

implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
Run Code Online (Sandbox Code Playgroud)
implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '3.0.0'
Run Code Online (Sandbox Code Playgroud)
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
Run Code Online (Sandbox Code Playgroud)