/**
*
-
设置跨域请求
/
@Configuration
public class CorsConfig {
private Logger logger = LoggerFactory.getLogger(CorsConfig.class);
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("“); // 1 设置访问源地址
corsConfiguration.addAllowedHeader(”“); // 2 设置访问源请求头
corsConfiguration.addAllowedMethod(”"); // 3 设置访问源请求方法
logger.info(“CorsConfig:设置跨域请求结束”);
return corsConfiguration;
}@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration(“/**”, buildConfig()); // 4 对接口配置跨域设置
logger.info(“CorsConfig:对接口配置跨域设置结束”);
return new CorsFilter(source);
}
}