0
点赞
收藏
分享

微信扫一扫

SpringBoot 2.4.0版本后解决跨域问题


package com.atguigu.gulimall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
* @author xh
* @Date 2022/1/28
*/
@Configuration
public class GulimallCrosConfiguration {

@Bean
public CorsWebFilter corsWebFilter() {

CorsConfiguration corsConfiguration = new CorsConfiguration();
//1,允许任何来源
corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*"));
//2,允许任何请求头
corsConfiguration.addAllowedHeader(CorsConfiguration.ALL);
//3,允许任何方法
corsConfiguration.addAllowedMethod(CorsConfiguration.ALL);
//4,允许凭证
corsConfiguration.setAllowCredentials(true);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfiguration);
return new CorsWebFilter(source);
}
}

可能会报的错:

SpringBoot 2.4.0版本后解决跨域问题_spring boot


导错包啦!

SpringBoot 2.4.0版本后解决跨域问题_java_02


举报

相关推荐

0 条评论