Spring Reactive xml有效负载异常java.lang.IllegalStateException:无法解析类型为“reactor.core.publisher.Mono”的参数0

2024-03-19

我有一个春季启动应用程序。尝试通过邮递员将 xml 有效负载发送到 Post 请求。我得到以下内容例外

java.lang.IllegalStateException: Failed to resolve argument 0 of type 'reactor.core.publisher.Mono' on public reactor.core.publisher.Mono<com.event.gateway.rest.controller.Sir> com.event.gateway.rest.controller.WBController.hello(reactor.core.publisher.Mono<com.event.gateway.rest.controller.Sir>)
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.getArgumentError(InvocableHandlerMethod.java:198) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:193) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$null$1(InvocableHandlerMethod.java:149) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at java.util.Optional.orElseGet(Optional.java:267) ~[na:1.8.0_91]
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$resolveArguments$2(InvocableHandlerMethod.java:147) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_91]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_91]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_91]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_91]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_91]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_91]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_91]
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArguments(InvocableHandlerMethod.java:153) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:117) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter.lambda$handle$3(RequestMappingHandlerAdapter.java:312) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at reactor.core.publisher.MonoThenMap$MonoThenApplyMain.onNext(MonoThenMap.java:100) [reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:928) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore$MonoThenIgnoreMain.drain(MonoThenIgnore.java:145) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore.subscribe(MonoThenIgnore.java:54) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenMap.subscribe(MonoThenMap.java:57) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenMap$MonoThenApplyMain.onNext(MonoThenMap.java:130) [reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:68) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:78) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:263) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:743) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:119) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:928) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore$MonoThenAcceptSubscriber.onNext(MonoThenIgnore.java:261) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:1657) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore$MonoThenAcceptSubscriber.onSubscribe(MonoThenIgnore.java:250) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:59) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore$MonoThenIgnoreMain.drain(MonoThenIgnore.java:151) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore.subscribe(MonoThenIgnore.java:54) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoMapFuseable.subscribe(MonoMapFuseable.java:60) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:402) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:203) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:97) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:57) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.FluxConcatMap.subscribe(FluxConcatMap.java:126) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoNext.subscribe(MonoNext.java:41) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoOtherwiseIfEmpty.subscribe(MonoOtherwiseIfEmpty.java:44) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenMap.subscribe(MonoThenMap.java:57) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenMap.subscribe(MonoThenMap.java:57) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoOtherwise.subscribe(MonoOtherwise.java:44) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoOtherwise.subscribe(MonoOtherwise.java:44) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoOtherwise.subscribe(MonoOtherwise.java:44) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore$MonoThenIgnoreMain.drain(MonoThenIgnore.java:169) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoThenIgnore.subscribe(MonoThenIgnore.java:54) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoOtherwise.subscribe(MonoOtherwise.java:44) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.core.publisher.MonoPeekTerminal.subscribe(MonoPeekTerminal.java:62) ~[reactor-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at reactor.ipc.netty.channel.ChannelOperations.applyHandler(ChannelOperations.java:405) ~[reactor-netty-0.6.1.RELEASE.jar:0.6.1.RELEASE]
    at reactor.ipc.netty.http.server.HttpServerOperations.onHandlerStart(HttpServerOperations.java:353) ~[reactor-netty-0.6.1.RELEASE.jar:0.6.1.RELEASE]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[netty-all-4.1.8.Final.jar:4.1.8.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403) ~[netty-all-4.1.8.Final.jar:4.1.8.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445) ~[netty-all-4.1.8.Final.jar:4.1.8.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[netty-all-4.1.8.Final.jar:4.1.8.Final]
    at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_91]
Caused by: java.lang.UnsupportedOperationException: null
    at org.springframework.core.codec.AbstractDecoder.decodeToMono(AbstractDecoder.java:64) ~[spring-core-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.http.codec.DecoderHttpMessageReader.readMono(DecoderHttpMessageReader.java:84) ~[spring-web-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.reactive.result.method.annotation.AbstractMessageReaderArgumentResolver.readBody(AbstractMessageReaderArgumentResolver.java:160) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.reactive.result.method.annotation.RequestBodyArgumentResolver.resolveArgument(RequestBodyArgumentResolver.java:78) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:184) ~[spring-webflux-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
    ... 56 common frames omitted

下面给出的是 POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.event.gateway</groupId>
    <artifactId>endpoint-rest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>vu-ms-event-gateway</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


</project>

控制器

package com.event.gateway.rest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;



@Controller
public class WBController {

    @RequestMapping(value ="hello", consumes ="application/xml", produces="application/xml", method=RequestMethod.POST)
    @ResponseBody
    public Mono <Sir> hello(@RequestBody Mono<Sir> requestBody) {
        Flux<String> mono =  Mono.just("")
                .concatWith(Mono.from(requestBody)
                        .flatMap(sir -> Flux.fromArray(sir.getLastName().split("")))
                        .map(String::toUpperCase)
                        .take(4)
                );


            mono.subscribe(System.out::println);
    return requestBody;
    }
}

POJO类

package com.event.gateway.rest.controller;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.annotation.JsonInclude;
import javax.xml.bind.annotation.XmlAccessType;
@JsonInclude(JsonInclude.Include.NON_NULL)
@XmlRootElement(name="sir")
@XmlAccessorType(XmlAccessType.FIELD)
public class Sir implements Serializable {

    private static final long serialVersionUID = 1L;
    @XmlElement(name ="firstName")
    private String firstName;

    @XmlElement(name ="lastName")
    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

}

邮递员请求示例

POST /hello HTTP/1.1
Host: localhost:8070
Content-Type: application/xml
Cache-Control: no-cache
Postman-Token: 2132d866-347e-5fcf-de00-2dc8f5f97ac0

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sir>
    <firstName>Jane Doe</firstName>
    <lastName>Peter</lastName>
</sir>

我收到 500 内部服务器错误作为响应。

非常感谢您的帮助。


不知道为什么,但据我所知它使用Jaxb2XmlDecoder用于解码 XML 有效负载和decodeToMono方法没有在那里实现。

要解决此问题,您可以使用Flux<Sir>输入为requestBody

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Reactive xml有效负载异常java.lang.IllegalStateException:无法解析类型为“reactor.core.publisher.Mono”的参数0 的相关文章

随机推荐

  • 更新到 3.0 后 Gradle 构建失败

    我最近将项目的 gradle 版本从 2 14 1 更新到 3 0 从那时起 gradle 构建每次都会失败 并出现以下错误 错误 原因 org gradle api internal tasks DefaultTaskInputs Tas
  • 分组表视图

    我想创建一个如下图所示的表格视图 谁能告诉我一个例子或者说我该怎么做 创建一个 UITableView 并将样式设置为 UITableViewStyleGrouped 您可以通过编程方式或在 IB 中执行此操作 然后您需要 2 个部分 第一
  • 如何卸载Keras?

    我已经使用以下命令安装了 Keras sudo pip install keras 它安装正确并且工作正常 直到我尝试导入应用程序模块 from keras applications vgg16 import VGG16 Using The
  • 如何解决 Spark JDBC 的编码问题?

    我在 Oracle 中有一个表 其中有一些俄语记录 当我使用 Spark JDBC 读取此表时 我收到的数据帧的值不正确 您知道为什么会发生这种情况以及如何解决吗 executes given query using jdbc def ex
  • 将UserTrackingMode 设置为 MKUserTrackingModeFollow 而不更改缩放级别

    在 Apple 文档中设置用户跟踪模式 动画 https developer apple com library ios documentation MapKit Reference MKMapView Class index html a
  • 以 Kotlin 方式获取字符串中包含的子字符串的索引

    我想实现一个函数 它将返回指定字符串中子字符串的索引 现在我用Java风格做了 public fun String indexesOf substr String ignoreCase Boolean true List
  • 使用 SASS 函数自动设置嵌套元素的背景颜色

    我正在制作一个多级导航系统 并希望每个级别的背景颜色变暗 20 因此第 1 级 fff 第 2 级 ccc 第 3 级 999 等等 一定有一种很棒的方法可以使用 SASS 函数动态地自动化这个过程 但我不太明白如何设置该语句 有人能指出我
  • ActiveRecord 搜索返回“语法错误或访问冲突”错误

    在我的 Yii 应用程序中 我有一个模型代表siteconfig表并有四列 integer config id string key string value string update time 我使用Gii创建了一个模型 以确保我不会犯
  • 如何*快速*将许多 .txt 文件转换为 .xls 文件

    更新 我刚刚发现拥有更强大服务器的人将完成分配给我的任务 所以我没有让这个程序足够快也没关系 然而 下面的答案 自动化 Excel 有助于使程序速度提高三倍 因此我将其推荐给文件较少 但仍然较多 的人 我正在尝试将许多 超过 300 000
  • Java泛型通配符及其局限性

    我有一个由两部分组成的问题 我的书指出 如果指定通配符时没有大写字母 绑定 那么只能调用 Object 类型的方法 通配符类型的值 我不知道这意味着什么 这是什么意思 另外 通配符类型 无界和有界 有哪些限制 例如 如果我有一个参考MyCl
  • 来自相机的原始图像数据

    我一直在这个论坛上上下搜索 但找不到我真正需要的东西 我想从相机获取原始图像数据 到目前为止 我尝试通过该方法从 imageDataSampleBuffer 中获取数据captureStillImageAsynchronouslyFromC
  • 如何组合多个 TypeScript 类装饰器?

    我有一个类装饰器家族 我在很多类中重复使用它们 与此类似的东西 foo bar baz export class MyClass 由于我在多个类中使用这三个装饰器 我真的很想将其分解为一个装饰器 如下所示 standard export c
  • 如何获取 C# 中所有已加载类型的列表?

    我需要检索从给定的程序集加载的所有枚举 List
  • 导入错误? (Python 3.2)

    我有自己的名为 v systems 的模块 并且我正在尝试将该模块导入到另一个 python 文件中 该文件也保存在与保存文件 v systems 相同的目录中 我需要将其导入为import v systems as vs或者即使我尝试导入
  • 以概率打乱 JS 数组

    假设我有一个像这样的数组 const alphabet a b c d 这代表 4 名政治候选人和一次等级选择投票 其中候选人a是首选 b是第二选择等等 我想将其打乱为一堆随机顺序 但在这种情况下我想要a大概以 60 的比例最先出现 b第二
  • Android Studio - 没有可调试的应用程序

    我尝试调试 Android 应用程序的发布版本 但 Android Studio 无法附加调试器 它找不到我正在运行的应用程序的 Android 进程 在设备控制台下 只有一条消息 没有可调试的应用程序 您还应该激活 工具 gt Andro
  • CMake 中的第三方库

    我在我的项目中使用 cmake 但我在子目录 例如 lib 中有另一个库 它使用普通的 Makefile 作为构建过程的一部分 如何指示 CMake 运行 lib 中的 Makefile 解决方案是使用 execute process CO
  • 安装后将 Javacard 小程序标记为隐式可选(默认小程序)

    我正在寻找一种方法 将小程序标记为隐式可选 默认选择 小程序 然后将其上传并安装在全球平台 http www globalplatform org JCOP 2 4 2 R1 http www nxp com products identi
  • 使用 JAVA 在 S3 存储桶上放置/读取文件

    我试图将文件放在 S3 上并使用 JAVA 从 S3 存储桶读取文件 但遇到无法执行 HTTP 请求 当我尝试列出存储桶时 它工作正常 对我来说 似乎只有 listBuckets 方法在工作 而所有其他方法 如 putObject list
  • Spring Reactive xml有效负载异常java.lang.IllegalStateException:无法解析类型为“reactor.core.publisher.Mono”的参数0

    我有一个春季启动应用程序 尝试通过邮递员将 xml 有效负载发送到 Post 请求 我得到以下内容例外 java lang IllegalStateException Failed to resolve argument 0 of type