Spring CORS No 'Access-Control-Allow-Origin' header is present

后端 未结 11 1199
半阙折子戏
半阙折子戏 2020-11-30 18:21

I am getting the following problem after porting web.xml to java config

No \'Access-Control-Allow-Origin\' header is present on the requested resource. Origi         


        
11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 19:09

    I also had messages like No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.

    I had configured cors properly, but what was missing in webflux in RouterFuncion was accept and contenttype headers APPLICATION_JSON like in this piece of code:

    @Bean
    RouterFunction routes() {
        return route(POST("/create")
                                  .and(accept(APPLICATION_JSON))
                                  .and(contentType(APPLICATION_JSON)), serverRequest -> create(serverRequest);
    }
    

提交回复
热议问题