美文网首页
springboot跨域配置

springboot跨域配置

作者: 诗酒趁年华_d593 | 来源:发表于2020-10-30 14:57 被阅读0次
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.cors.CorsConfiguration;
    import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
    import org.springframework.web.filter.CorsFilter;
    
    
    @Configuration
    public class CrossConfig {
        @Bean
        public CorsFilter corsFilter() {
            CorsConfiguration config = new CorsConfiguration();
            config.addAllowedOrigin("*");
            config.setAllowCredentials(true);
            config.addAllowedMethod("*");
            config.addAllowedHeader("*");
            UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
            configSource.registerCorsConfiguration("/**", config);
            return new CorsFilter(configSource);
        }
    }
    

    相关文章

      网友评论

          本文标题:springboot跨域配置

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