009-Spring Boot全局配置跨域请求支持
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全局配置跨域请求支持的更多相关文章
- spring boot之配置跨域
在启动类中配置 @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override p ...
- spring boot项目配置跨域
1.在项目启动入口类实现 WebMvcConfigurer 接口: @SpringBootApplication public class Application implements WebMvcC ...
- Spring Boot Web应用开发 CORS 跨域请求支持:
Spring Boot Web应用开发 CORS 跨域请求支持: 一.Web开发经常会遇到跨域问题,解决方案有:jsonp,iframe,CORS等等CORS与JSONP相比 1. JSONP只能实现 ...
- NGINX: 配置跨域请求
说明: 内容全部来自 SegmentFault Developer Nginx 配置跨域请求 跨域请求失败, nginx 报错: 403 No 'Access-Control-Allow-Origin ...
- Spring 完美配置跨域请求
在SpringBoot2.0 上的跨域 用以下代码配置 即可完美解决你的前后端跨域请求问题 import org.springframework.context.annotation.Bean; im ...
- Vue-cli 创建的项目配置跨域请求(通过反向代理)---配置多个代理--axios请求
问题描述: 使用 Vue-cli 创建的项目,开发地址是 localhost:8080,需要访问 localhost:9000 或https://m.maoyan.com或http://image.b ...
- Nginx配置跨域请求 CORS
当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...
- Nginx配置跨域请求 Access-Control-Allow-Origin *
当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...
- Nginx配置跨域请求“Access-Control-Allow-Origin”
当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...
随机推荐
- Spring4 -03 -Dependency Injection (依赖注入) : 代码体现/配置xml/测试
DI:中文名称:依赖注入 英文名称((Dependency Injection) DI 是什么? 3.1 DI 和IoC 是一样的,差不多一样的技术和模板! 3.2 当一个类(A)中需要依赖另一个类( ...
- 《你又怎么了我错了行了吧》【Beta】Scrum meeting 3
第三天 日期:2019/6/26 前言: 第3次会议在女生宿舍召开(前一天晚上开的) 项目全部基本测试完成,解决了多处bug,明天终于可以拿去演示了.... 1.1 今日完成任务情况.成员贡献时间及工 ...
- maven 项目打包配置(build节点)
参考博客:https://www.cnblogs.com/Binhua-Liu/p/5604841.html maven-assembly-plugin的使用 : https://www.cnblog ...
- linux第三天
一.用户的类型 1.root管理员:所有权限(r w x) 2.文件拥有者(u):谁创建谁拥有 3.组 (g):用户组 4.其它用户(o):不属于用户组,也不是文件的创建者,不是管理员 ...
- [RxJS] Subject asObservable() method
You can create your own state store, not using any state management libraray. You might have seen th ...
- go同步互斥锁
import "sync" var ( myMap = make(map[int]int, 10) lock sync.Mutex //声明一个全局的互斥锁 //sync 包 同步 ...
- Apache Solr Velocity模板远程代码执行
更多内容,欢迎关注微信公众号:信Yang安全,期待与您相遇. 这里用的docker环境 很简单的 在这里不再介绍 本地搭建好环境然后访问8983端口 网页如下: 查下节点名称 同样名字可以访问http ...
- Linux rpm安装指定安装路径
可以使用prefix参数. rpm -i –prefix=/home/gpadmin greenplum-db-6.0.0-rhel6-x86_64.rpm 将greenplum-db-6.0. ...
- leaning java swing 为组件设置边框
import javax.swing.*; import javax.swing.border.BevelBorder; import javax.swing.border.Border; impor ...
- 洛谷 P1004 方格取数 题解
P1004 方格取数 题目描述 设有 \(N \times N\) 的方格图 \((N \le 9)\),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字\(0\).如下图所示(见样例): ...