Spring Security 的配置
http
//跨域配置開始
.cors().disable()
.cors()
.and()
.authorizeRequests()
.requestMatchers(CorsUtils::isPreFlightRequest)
.permitAll()
//跨域配置結束
.and()

image.png
然后可能會出現(xiàn)OPTIONS
//解決前端跨域
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*")
.allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
.allowCredentials(true).maxAge(3600);
}

image.png