1、Spring Boot 2.0以前全局配置跨域主要是继承WebMvcConfigurerAdapter

@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter { @Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("*")
.maxAge(3600);
}
}

2、2.0.x以后全局配置如下,主要是实现WebMvcConfigurer

@Configuration
@EnableWebMvc
public class CorsConfig implements WebMvcConfigurer { @Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路径
registry.addMapping("/**")
// 设置允许跨域请求的域名
.allowedOrigins("*")
// 是否允许证书 不再默认开启
.allowCredentials(true)
// 设置允许的方法
.allowedMethods("*")
// 跨域允许时间
.maxAge(3600);
}
}

3、局部配置

@GetMapping("/getPageInfos")
@CrossOrigin
public JSONObject getPageInfos(@RequestParam(value = "resourceId") long resourceId,
@RequestParam(value = "range", required = false) int[] range,HttpServletResponse response) {
response.setHeader("Access-Control-Allow-Origin", "*");
// do sth...
}

009-Spring Boot全局配置跨域请求支持的更多相关文章

  1. spring boot之配置跨域

    在启动类中配置 @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override p ...

  2. spring boot项目配置跨域

    1.在项目启动入口类实现 WebMvcConfigurer 接口: @SpringBootApplication public class Application implements WebMvcC ...

  3. Spring Boot Web应用开发 CORS 跨域请求支持:

    Spring Boot Web应用开发 CORS 跨域请求支持: 一.Web开发经常会遇到跨域问题,解决方案有:jsonp,iframe,CORS等等CORS与JSONP相比 1. JSONP只能实现 ...

  4. NGINX: 配置跨域请求

    说明: 内容全部来自 SegmentFault Developer Nginx 配置跨域请求 跨域请求失败, nginx 报错: 403 No 'Access-Control-Allow-Origin ...

  5. Spring 完美配置跨域请求

    在SpringBoot2.0 上的跨域 用以下代码配置 即可完美解决你的前后端跨域请求问题 import org.springframework.context.annotation.Bean; im ...

  6. Vue-cli 创建的项目配置跨域请求(通过反向代理)---配置多个代理--axios请求

    问题描述: 使用 Vue-cli 创建的项目,开发地址是 localhost:8080,需要访问 localhost:9000 或https://m.maoyan.com或http://image.b ...

  7. Nginx配置跨域请求 CORS

    当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...

  8. Nginx配置跨域请求 Access-Control-Allow-Origin *

    当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...

  9. Nginx配置跨域请求“Access-Control-Allow-Origin”

    当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...

随机推荐

  1. 如何防护DDOS攻击策略

    DDoS是目前最凶猛.最难防御的网络攻击之一.现实情况是,这个世界级难题还没有完美的.彻底的解决办法,但采取适当的措施以降低攻击带来的影响.减少损失是十分必要的.将DDoS防御作为整体安全策略的重要部 ...

  2. JAVA BIO至NIO演进

    主要阐述点: 1.同步/异步 or  阻塞/非阻塞 2.网络模型演进 3.NIO代码示例 一.同步/异步 or  阻塞/非阻塞 同步/异步:核心点在于是否等待结果返回.同步即调用者必须等到结果才返回, ...

  3. javamail: UrlDataSource获取网络文件作为邮件的附件|javamail发送二进制流附件的问题

    https://www.cnblogs.com/younldeace/p/5193103.html 最近做个邮件发送功能,要内嵌图片并有附件. 需求很奇怪,图片和附件文件是放在ftp服务器上的,查了下 ...

  4. Tensorflow细节-P170-图像数据预处理

    由于6.5中提出的TFRecord非常复杂,可扩展性差,所以本节换一种方式 import tensorflow as tf from tensorflow.examples.tutorials.mni ...

  5. 洛谷 P1854 花店橱窗布置 题解

    Analysis 给定一个f*v的矩阵 要求从第一行走到第f行,每行取走一个数, 且该行所取的数必须必上一行所取的数的列数大 , 求所能取走的最大值 注意每一行所取走的数字的列数必须大于等该行的行号 ...

  6. BCB key事件中判断Shift、Alt、Ctrl状态

    BCB key事件中判断Shift.Alt.Ctrl状态: 类似此事件中 void __fastcall TForm1::keydown(TObject *Sender, WORD &Key, ...

  7. ipkg-nas

    http://pkg.entware.net/binaries/x86-64/ https://forum.synology.com/enu/viewtopic.php?t=95346 http:// ...

  8. Deepin Create/Delete Folder refresh

    Did u have a problem whth the deepin file manager,Everthime I create/delete a Folder of File i have ...

  9. css笔记 - flex弹性盒布局

    flex: display:-webkit-box | -moz-box;盒布局 -webkit-box-flex | -moz-box-flex;弹性盒布局 -webkit-box-ordinal- ...

  10. SpringBoot获取Freemarker模板引擎,生成HTML代码

    今天用Ajax异步添加评论,加载Freemarker模板引擎,生成模板模块 1.新建Freemarker模板 <li id="${comment.oId}"> < ...