springboot-跨域配置 /** * 解决跨域问题 * 开发环境dev才会生效 * 如果不需要解决跨域问题,则别让该过滤器起作用 */@Configurationpublic class CustomCORSConfiguration {private CorsConfiguration buildConfig()
/** * 解决跨域问题 * 开发环境dev才会生效 * 如果不需要解决跨域问题,则别让该过滤器起作用 */ @Configuration public class CustomCORSConfiguration { private CorsConfiguration buildConfig() { CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("*"); corsConfiguration.addAllowedHeader("*"); corsConfiguration.addAllowedMethod("*"); return corsConfiguration; } @Bean @Profile(value = "dev") public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", buildConfig()); return new CorsFilter(source); } }