springboot 跨域设置

Posted 焦虑的soul

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot 跨域设置相关的知识,希望对你有一定的参考价值。

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

以上是关于springboot 跨域设置的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot 设置前端跨域

springboot 跨域设置

springboot跨域不拦截json拦截文件

SpringBoot自定义拦截器和跨域配置冲突

springboot+vue跨域问题

Springboot 配置跨域