网关配置类

  • Post author:
  • Post category:其他


网关配置类



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;
import org.springframework.web.util.pattern.PathPatternParser;

/**
 * @author root
 * @create 2021-06-24 14:35
 */
@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");// 允许任何方法(post、get等)
        config.addAllowedOrigin("*");// 允许任何域名使用
        config.addAllowedHeader("*");// 允许任何头
        config.setAllowCredentials(true);//允许接受cookie
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);
        return new CorsWebFilter(source);
    }
}



版权声明:本文为weixin_45873488原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。