LoginSignup
1
0

More than 3 years have passed since last update.

webflux POSTのbodyを @RequestBody で受けると Only one connection receive subscriber allowed になる問題の回避方法

Last updated at Posted at 2019-08-05

webfluxで@PostMappingに来るリクエストのbodyを@RequestBodyで受けようとするとエラーになる。

https://github.com/spring-projects/spring-framework/issues/22284
この辺

HiddenHttpMethodFilter でリクエストの中身を見ているのがダメっぽい。
POSTで他のHTTP Methodを再現できる機能があり、使っていないのであれば回避すれば問題は解決できる。

方法は自分で無効なHiddenHttpMethodFilterのBeanを登録する。
(リクエストのContent−Typeをtext/plainとかにしても行けるが、こんな御事情のためにわざわざリクエストに手を加えて対応というのはかなり厳しい感じがする)

@Component
public class AvoidHiddenHttpMethodFilter extends HiddenHttpMethodFilter {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        // just do it
        return chain.filter(exchange);
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0