定义跨域ip 域名
cors.addMapping=/** cors.allowedOrigins=http://localhost,http://localhost:8080,https://www.baidu.com cors.allowCredentials=true cors.allowedMethods=GET,POST,PUT,DELETE,OPTIONS cors.max_age=3600
@ConfigurationProperties( prefix = "cors" ) public class CorsProperties { private String addMapping; private String[] allowedOrigins; private Boolean allowCredentials; private String[] allowedMethods; private Integer maxAge; }
@Configuration @EnableConfigurationProperties({CorsProperties.class}) public class CorsConfig implements WebMvcConfigurer { @Autowired private CorsProperties properties; public CorsConfig() { } public void addCorsMappings(CorsRegistry registry) { registry.addMapping(this.properties.getAddMapping()) .allowedOrigins(this.properties.getAllowedOrigins()) .allowCredentials(this.properties.getAllowCredentials()) .allowedMethods(this.properties.getAllowedMethods()) .maxAge((long) this.properties.getMaxAge()); } }