Spring Global CORS configuration not working but Controller level config does

后端 未结 10 1101
臣服心动
臣服心动 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:08

    I was trying to configure CORS globally via WebMvcConfigurerAdapter shown yours with log. And I found log message but it got error like

    Access to XMLHttpRequest at 'myurl' from origin 'some origin' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Controll-Allow-Origin' header is presnet on the requested resource.

    My Case was also good at @CrossOrigin but not in globally configure. I hope this will be helped.

    The reason is web.xml.

    1. I have but class WebConfig is not in 'some base-package' package, It's in the upper package. I moved WebConfig to 'some base-package' package and

    2. I removed because I have already have @EnableWebMvc in WebConfig class.

    It works.

提交回复
热议问题