Spring Global CORS configuration not working but Controller level config does

后端 未结 10 1075
臣服心动
臣服心动 2020-12-14 06:25

I am trying to configure CORS globally via WebMvcConfigurerAdapter shown below. To test I am hitting my API endpoint via a small node app I created to emulate a

10条回答
  •  自闭症患者
    2020-12-14 07:11

    I was able to get the Spring Global CORS configuration to work, after experiencing the exact problem documented in this issue. I had to do 2 things:

    1. allowedOrigins cannot be * if allowCredentials is true. This is documented at Mozilla.org

    2. Remove mvc:annotation-driven from the spring XML. Cannot have BOTH the XML config and @EnableWebMvc. The global class won't work without @EnableWebMvc, thus mvc:annotation-driven must be removed.

提交回复
热议问题