Spring Security 的配置
http
//跨域配置开始
.cors().disable()
.cors()
.and()
.authorizeRequests()
.requestMatchers(CorsUtils::isPreFlightRequest)
.permitAll()
//跨域配置结束
.and()
image.png
然后可能会出现OPTIONS
//解决前端跨域
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*")
.allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
.allowCredentials(true).maxAge(3600);
}
image.png
网友评论