GET方式出现跨域,别的请求方式没事
如果 //config.addAllowedMethod("*"); 就会出现这个问题,ResponsHeaders缺少Access-Control-Allow-Origin: *,别的请求方式没问题。
package cn.opendatachain.manage.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* CorsConfig Description
*
* @author lishijian
* @version odc-manage 1.0.0.RELEASE
* <b>Creation Time:</b> 2021/12/17 16:53
*/
@Configuration
public class CorsConfig{
@Bean
@Order(-200) //非常重要,一定要早于AuthFilter
public CorsWebFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
//config.addAllowedMethod("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);
}
}
解决问题:每种请求方式单独写出来就好了,ResponsHeaders缺少Access-Control-Allow-Origin: * 也会有
网友评论