编程语言
首页 > 编程语言> > java web解决跨域问题,亲测有效!

java web解决跨域问题,亲测有效!

作者:互联网

@Configuration
public class BeanConfiguration {
    @Bean
     public CorsFilter corsFilter() {
                final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
                final CorsConfiguration corsConfiguration = new CorsConfiguration();
                corsConfiguration.setAllowCredentials(true);
                 corsConfiguration.addAllowedOrigin("*");
                 corsConfiguration.addAllowedHeader("*");
                 corsConfiguration.addAllowedMethod("*");
                 urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
                 return new CorsFilter(urlBasedCorsConfigurationSource);
             }

}

自定义配置类,加入该代码,即可解决!

标签:web,java,跨域,corsConfiguration,CorsConfiguration,new,UrlBasedCorsConfigurationSou
来源: https://blog.51cto.com/u_15257216/2861473