Spring boot 跨域请求问题(403)

解决方案:

/**
 * 设置跨域请求
 */
@Configuration
public class MyConfiguration {
    @Bean
    public FilterRegistrationBean corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");// 1 设置访问源地址
        config.addAllowedHeader("*");// 2 设置访问源请求头
        config.addAllowedMethod("*");// 3 设置访问源请求方法
        source.registerCorsConfiguration("/**", config);
        FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
        bean.setOrder(0);
        return bean;
    }
}

You may also like...

1 Response

  1. cialis说道:

    you are truly a excellent webmaster. The website
    loading velocity is incredible. It sort of feels that you
    are doing any distinctive trick. Furthermore, The contents are masterwork.
    you have done a fantastic job on this topic!

发表评论

电子邮件地址不会被公开。 必填项已用*标注