美文网首页
spring boot 后台解决跨域

spring boot 后台解决跨域

作者: 紫薇大舅 | 来源:发表于2017-12-26 17:16 被阅读0次

    创建SecurityCorsConfiguration类文件

    @Configuration
    public class SecurityCorsConfiguration {
    
        @Bean
        public FilterRegistrationBean corsFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            CorsConfiguration config = new CorsConfiguration();
            config.setAllowCredentials(true);
            config.addAllowedOrigin("*");
            config.addAllowedHeader(CorsConfiguration.ALL);
            config.addAllowedMethod(CorsConfiguration.ALL);
            source.registerCorsConfiguration("/**", config);
            FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
            bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
            return bean;
        }
    }
    

    相关文章

      网友评论

          本文标题:spring boot 后台解决跨域

          本文链接:https://www.haomeiwen.com/subject/waejgxtx.html