码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-06-26 15:04:52      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:str   col   extend   err   desc   origin   rip   dma   web   

 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 }

 

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

标签:str   col   extend   err   desc   origin   rip   dma   web   

原文地址:https://www.cnblogs.com/Java-Script/p/11089859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!