Spring Boot全局支持CORS(跨源请求)

 1 import org.springframework.context.annotation.Configuration;
 2 import org.springframework.web.servlet.config.annotation.CorsRegistry;
 3 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 4 
 5 /**
 6  * @Author:CoderZZ
 7  * @Description:Spring Boot全局支持CORS(跨源请求)
 8  * @Date:Created in 10:57 2018/2/8.
 9  */
10 @Configuration
11 public class WebCorsConfigurerAdapter extends WebMvcConfigurerAdapter
12 {
13 
14     @Override
15     public void addCorsMappings(CorsRegistry registry) {
16         registry.addMapping("/**").
17                 allowedOrigins("*").
18                 allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS").
19                 allowedHeaders("Content-Type","Access-Control-Allow-Headers","Authorization","X-Requested-With").
20                 allowCredentials(true);
21     }
22 }
原文地址:https://www.cnblogs.com/Java-Script/p/11089859.html