Spring boot 解決跨域問題配置類

陳漂流發表於2020-12-22

Spring boot 解決跨域問題配置類

@Configuration
public class CorsConfig {

    //解決跨域問題
    @Bean
    public CorsWebFilter corsWebFilter(){

        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**",config);

        return new CorsWebFilter(source);
    }

}

相關文章