“spring webflux所有API都报UnsupportedMediaTypeException错误。”

huangapple go评论184阅读模式
英文:

spring webflux all api's giving UnsupportedMediaTypeException

问题

  1. 我有一个`@SpringBootApplication`使用Gson而不是Jackson以下是使用以下转换器的代码
  2. ```java
  3. @Configuration
  4. public class ApplicationConfiguration {
  5. @Bean
  6. public GsonBuilder gsonBuilder(){
  7. final GsonBuilder gsonBuilder = new GsonBuilder();
  8. // 在这里注册TypeAdapter
  9. return gsonBuilder;
  10. }
  11. }

现在我有一个控制器(所有控制器都会失败,不仅是这个,但它们的语法相同):

  1. @RestController("/1/api/release/")
  2. @Log
  3. @RequiredArgsConstructor
  4. public class ReleaseController {
  5. @PostMapping("blocked")
  6. public Mono<ServerResponse> issueIsBlocked() {
  7. return Mono.just("test")
  8. .flatMap(s -> ServerResponse.ok().bodyValue(s))
  9. .onErrorResume(Throwable.class, e -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).bodyValue(e.getMessage()));
  10. }
  11. }

而且application.properties包含:

  1. spring.http.converters.preferred-json-mapper=gson
  2. spring.codec.max-in-memory-size=10MB

然而,我得到了这个错误:

  1. org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json' not supported for bodyType=java.util.LinkedHashMap<?, ?>

我的pom.xml文件:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <artifactId>testing</artifactId>
  7. <packaging>pom</packaging>
  8. <parent>
  9. <groupId>org.springframework.boot</groupId>
  10. <artifactId>spring-boot-starter-parent</artifactId>
  11. <version>2.2.5.RELEASE</version>
  12. </parent>
  13. <groupId>com.dummy</groupId>
  14. <version>0.0.1-SNAPSHOT</version>
  15. <properties>
  16. <java.version>11</java.version>
  17. </properties>
  18. <dependencies>
  19. <dependency>
  20. <groupId>org.springframework.boot</groupId>
  21. <artifactId>spring-boot-starter-webflux</artifactId>
  22. <!-- 排除默认的Jackson依赖 -->
  23. <exclusions>
  24. <exclusion>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-json</artifactId>
  27. </exclusion>
  28. </exclusions>
  29. </dependency>
  30. <dependency>
  31. <groupId>org.projectlombok</groupId>
  32. <artifactId>lombok</artifactId>
  33. <optional>true</optional>
  34. </dependency>
  35. <dependency>
  36. <groupId>org.apache.commons</groupId>
  37. <artifactId>commons-lang3</artifactId>
  38. <version>3.9</version>
  39. </dependency>
  40. <dependency>
  41. <groupId>com.google.code.gson</groupId>
  42. <artifactId>gson</artifactId>
  43. <version>2.8.4</version>
  44. </dependency>
  45. </dependencies>
  46. <build>
  47. <plugins>
  48. <plugin>
  49. <groupId>org.springframework.boot</groupId>
  50. <artifactId>spring-boot-maven-plugin</artifactId>
  51. </plugin>
  52. <plugin>
  53. <groupId>org.apache.maven.plugins</groupId>
  54. <artifactId>maven-surefire-plugin</artifactId>
  55. </plugin>
  56. </plugins>
  57. </build>
  58. </project>

我注意到的事情:

  • 错误出现在我的方法被调用之前,因此与在方法中指定的错误处理无关。
  • 我尝试为LinkedHashMap添加类型适配器,但仍未被捕获。不过,如果需要的话,我目前只为WebClient添加了它们,但未考虑Spring如何处理转换。我在这里只是猜测,但我认为它会使用我在配置中指定的Gson bean。
  • 如果我查看BodyInserters:376中的context.messageWriters(),我看不到我明确添加的任何熟悉的内容。

我该如何使我的API正常工作?

  1. <details>
  2. <summary>英文:</summary>
  3. I have a `@SpringBootApplication` using Gson instead of jackson with the following converter:
  4. @Configuration
  5. public class ApplicationConfiguration {
  6. @Bean
  7. public GsonBuilder gsonBuilder(){
  8. final GsonBuilder gsonBuilder = new GsonBuilder();
  9. // I registerTypeAdapter &#39;s here
  10. return gson;
  11. }
  12. }
  13. I now have my controller (this fails on all of them not just this but they are the same syntax)
  14. @RestController(&quot;/1/api/release/&quot;)
  15. @Log
  16. @RequiredArgsConstructor
  17. public class ReleaseController {
  18. @PostMapping(&quot;blocked&quot;)
  19. public Mono&lt;ServerResponse&gt; issueIsBlocked() {
  20. return Mono.just(&quot;test&quot;)
  21. .flatMap(s -&gt; ServerResponse.ok().bodyValue(s))
  22. .onErrorResume(Throwable.class, e -&gt; ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).bodyValue(e.getMessage()));
  23. }
  24. }
  25. And application.properties contains
  26. spring.http.converters.preferred-json-mapper=gson
  27. spring.codec.max-in-memory-size=10MB
  28. I however get this error
  29. org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type &#39;application/json&#39; not supported for bodyType=java.util.LinkedHashMap&lt;?, ?&gt;
  30. at org.springframework.web.reactive.function.BodyInserters.unsupportedError(BodyInserters.java:391)
  31. at org.springframework.web.reactive.function.BodyInserters.lambda$writeWithMessageWriters$11(BodyInserters.java:381)
  32. at java.base/java.util.Optional.orElseGet(Optional.java:369)
  33. at org.springframework.web.reactive.function.BodyInserters.writeWithMessageWriters(BodyInserters.java:381)
  34. at org.springframework.web.reactive.function.BodyInserters.lambda$fromValue$1(BodyInserters.java:98)
  35. at org.springframework.web.reactive.function.server.DefaultServerResponseBuilder$BodyInserterResponse.writeToInternal(DefaultServerResponseBuilder.java:409)
  36. at org.springframework.web.reactive.function.server.DefaultServerResponseBuilder$AbstractServerResponse.writeTo(DefaultServerResponseBuilder.java:351)
  37. at org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler.write(AbstractErrorWebExceptionHandler.java:311)
  38. at org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler.lambda$handle$2(AbstractErrorWebExceptionHandler.java:264)
  39. at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:118)
  40. at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:203)
  41. at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1705)
  42. at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:144)
  43. at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67)
  44. at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67)
  45. at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2267)
  46. at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2075)
  47. at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:1949)
  48. at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54)
  49. at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
  50. at reactor.core.publisher.Mono.subscribe(Mono.java:4110)
  51. at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:75)
  52. at reactor.core.publisher.Operators.complete(Operators.java:135)
  53. at reactor.core.publisher.MonoEmpty.subscribe(MonoEmpty.java:45)
  54. at reactor.core.publisher.Mono.subscribe(Mono.java:4110)
  55. at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:97)
  56. at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:100)
  57. at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onError(FluxOnAssembly.java:390)
  58. at reactor.core.publisher.Operators.error(Operators.java:185)
  59. at reactor.core.publisher.MonoError.subscribe(MonoError.java:52)
  60. at reactor.core.publisher.Mono.subscribe(Mono.java:4110)
  61. at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:97)
  62. at reactor.core.publisher.MonoFlatMap$FlatMapMain.onError(MonoFlatMap.java:165)
  63. at reactor.core.publisher.MonoFlatMap$FlatMapMain.secondError(MonoFlatMap.java:185)
  64. at reactor.core.publisher.MonoFlatMap$FlatMapInner.onError(MonoFlatMap.java:251)
  65. at reactor.core.publisher.Operators$MonoSubscriber.onError(Operators.java:1752)
  66. at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreInner.onError(MonoIgnoreThen.java:235)
  67. at reactor.core.publisher.MonoFlatMap$FlatMapMain.onError(MonoFlatMap.java:165)
  68. at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onError(Operators.java:1944)
  69. at reactor.core.publisher.Operators.error(Operators.java:185)
  70. at reactor.core.publisher.MonoError.subscribe(MonoError.java:52)
  71. at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
  72. at reactor.core.publisher.Mono.subscribe(Mono.java:4110)
  73. at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:75)
  74. at reactor.core.publisher.MonoFlatMap$FlatMapMain.onComplete(MonoFlatMap.java:174)
  75. at reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.java:96)
  76. at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:359)
  77. at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:211)
  78. at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:161)
  79. at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86)
  80. at reactor.core.publisher.Mono.subscribe(Mono.java:4110)
  81. at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172)
  82. at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)
  83. at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)
  84. at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67)
  85. at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:76)
  86. at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:274)
  87. at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:851)
  88. at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:121)
  89. at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2267)
  90. at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:162)
  91. at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2075)
  92. at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:1949)
  93. at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onSubscribe(FluxMapFuseable.java:90)
  94. at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54)
  95. at reactor.core.publisher.Mono.subscribe(Mono.java:4110)
  96. at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:441)
  97. at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:211)
  98. at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:161)
  99. at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86)
  100. at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:55)
  101. at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
  102. at reactor.core.publisher.Mono.subscribe(Mono.java:4110)
  103. at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172)
  104. at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)
  105. at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:55)
  106. at reactor.netty.http.server.HttpServerHandle.onStateChange(HttpServerHandle.java:64)
  107. at reactor.netty.tcp.TcpServerBind$ChildObserver.onStateChange(TcpServerBind.java:228)
  108. at reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:465)
  109. at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:90)
  110. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
  111. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
  112. at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
  113. at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:170)
  114. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
  115. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
  116. at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
  117. at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
  118. at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:321)
  119. at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:295)
  120. at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
  121. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
  122. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
  123. at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
  124. at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
  125. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
  126. at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
  127. at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
  128. at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
  129. at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
  130. at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
  131. at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
  132. at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
  133. at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
  134. at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
  135. at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
  136. at java.base/java.lang.Thread.run(Thread.java:834)
  137. my pom.xml
  138. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  139. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
  140. xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  141. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  142. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  143. &lt;artifactId&gt;testing&lt;/artifactId&gt;
  144. &lt;packaging&gt;pom&lt;/packaging&gt;
  145. &lt;parent&gt;
  146. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  147. &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
  148. &lt;version&gt;2.2.5.RELEASE&lt;/version&gt;
  149. &lt;/parent&gt;
  150. &lt;groupId&gt;com.dummy&lt;/groupId&gt;
  151. &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  152. &lt;properties&gt;
  153. &lt;java.version&gt;11&lt;/java.version&gt;
  154. &lt;/properties&gt;
  155. &lt;dependencies&gt;
  156. &lt;dependency&gt;
  157. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  158. &lt;artifactId&gt;spring-boot-starter-webflux&lt;/artifactId&gt;
  159. &lt;!-- Exclude the default Jackson dependency --&gt;
  160. &lt;exclusions&gt;
  161. &lt;exclusion&gt;
  162. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  163. &lt;artifactId&gt;spring-boot-starter-json&lt;/artifactId&gt;
  164. &lt;/exclusion&gt;
  165. &lt;/exclusions&gt;
  166. &lt;/dependency&gt;
  167. &lt;dependency&gt;
  168. &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
  169. &lt;artifactId&gt;lombok&lt;/artifactId&gt;
  170. &lt;optional&gt;true&lt;/optional&gt;
  171. &lt;/dependency&gt;
  172. &lt;dependency&gt;
  173. &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
  174. &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
  175. &lt;version&gt;3.9&lt;/version&gt;
  176. &lt;/dependency&gt;
  177. &lt;dependency&gt;
  178. &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
  179. &lt;artifactId&gt;gson&lt;/artifactId&gt;
  180. &lt;version&gt;2.8.4&lt;/version&gt;
  181. &lt;/dependency&gt;
  182. &lt;/dependencies&gt;
  183. &lt;build&gt;
  184. &lt;plugins&gt;
  185. &lt;plugin&gt;
  186. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  187. &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  188. &lt;/plugin&gt;
  189. &lt;plugin&gt;
  190. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  191. &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  192. &lt;/plugin&gt;
  193. &lt;/plugins&gt;
  194. &lt;/build&gt;
  195. &lt;/project&gt;
  196. things i have noticed:
  197. - the error appears before my method is even entered, so it shouldn&#39;t really have anything to do with error handling specified there.
  198. - I tried adding type adapters for LinkedHashMap however they were still not caught. However if this is what is needed, I am currently only adding them for the WebClient not however spring is handling conversion. I am simply guessing here however I would assume it took the GSON bean i specified in my configuration, in which case it would be there.
  199. - If i look at BodyInserters:376 context.messageWriters() I see nothing familiar to stuff I added explicitly.
  200. How can I get my api&#39;s to work?
  201. </details>
  202. # 答案1
  203. **得分**: 2
  204. 你不应该在控制器中使用 `Mono&lt;ServerReponse&gt;`,因为它似乎没有被任何序列化器正确映射。
  205. 有两种替代方案:
  206. 1. 使用响应实体
  207. ```java
  208. @PostMapping("blocked")
  209. public Mono<ResponseEntity<String>> issueIsBlocked() {
  210. return Mono.just("test")
  211. .map(s -> new ResponseEntity<>(s, HttpStatus.OK))
  212. .onErrorResume(Throwable.class,
  213. e -> Mono.just(new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR))
  214. );
  215. }
  1. 使用 WebFlux 提供的 RouterFunction
  1. @Configuration
  2. public class RouterConfig {
  3. @Bean
  4. RouterFunction<ServerResponse> home() {
  5. return route(POST("/blocked"),
  6. request -> Mono.just("test")
  7. .flatMap(s -> ServerResponse.ok().bodyValue(s))
  8. .onErrorResume(Throwable.class, e ->
  9. ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).bodyValue(e.getMessage())
  10. ));
  11. }
  12. }
英文:

You are not supposed to use Mono&lt;ServerReponse&gt; in controllers, as such it doesn't appear to be mapped correctly by any serializer.

There are two alternatives

  1. Use response entity

    1. @PostMapping(&quot;blocked&quot;)
    2. public Mono&lt;ResponseEntity&lt;String&gt;&gt; issueIsBlocked() {
    3. return Mono.just(&quot;test&quot;)
    4. .map(s -&gt; new ResponseEntity&lt;&gt;(s, HttpStatus.OK))
    5. .onErrorResume(Throwable.class,
    6. e -&gt; Mono.just(new ResponseEntity&lt;&gt;(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR))
    7. );
    8. }

2.Use the RouterFunction provided by webflux

  1. @Configuration
  2. public class RouterConfig {
  3. @Bean
  4. RouterFunction&lt;ServerResponse&gt; home() {
  5. return route(POST(&quot;/blocked&quot;),
  6. request -&gt; Mono.just(&quot;test&quot;)
  7. .flatMap(s -&gt; ServerResponse.ok().bodyValue(s))
  8. .onErrorResume(Throwable.class, e -&gt;
  9. ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).bodyValue(e.getMessage())
  10. ));
  11. }

huangapple
  • 本文由 发表于 2020年4月4日 04:52:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/61020234.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定