前端請求接口時(shí)被盈,報(bào)跨域錯(cuò)誤,
錯(cuò)誤:Access to XMLHttpRequest at 'http://xxx.xx.xx.xx:xx/api/*?param=' from origin 'http://xxx:xxx' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
但是項(xiàng)目中是已經(jīng)配置了跨域請求SpringBoot 跨域請求
原因:
經(jīng)排查是oauth2 引起的律歼,我在oauth2的資源服務(wù)器中,配置資源服務(wù)器config時(shí)啡专,沒有配置跨域請求险毁,代碼如下:
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.requestMatchers()
.antMatchers("/api/v1/**");
}
解決方案:
添加 .and().cors(),完美解決問題。