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服 ...
随机推荐
- Java精通并发-wait与notify及线程同步系统总结
notifyAll(): 在上两次中对于Object的wait()和notify()方法的官方doc进行了通读,上一次https://www.cnblogs.com/webor2006/p/11407 ...
- 获取类范形的Class
public class Test<T>{ } Type genType = getClass().getGenericSuperclass(); Type[] params = ((Pa ...
- Union-Find(并查集): Quick union improvements
Quick union improvements1: weighting 为了防止生成高的树,将smaller tree放在larger tree的下面(smaller 和larger是指number ...
- 神经网络(9)--如何求参数: backpropagation algorithm(反向传播算法)
Backpropagation algorithm(反向传播算法) Θij(l) is a real number. Forward propagation 上图是给出一个training examp ...
- machine learning (3)---Linear Algebra Review
Matrix Vector Multiplication 左边的矩阵向量相乘法比右边的更简洁而且计算高效 Matrix Matrix Multiplication 可以同时计算12个结果(4个房子面积 ...
- 十二.Protobuf3编码
本文档描述了协议缓冲消息的二进制格式.在应用程序中使用Protocol Buffer不需要理解这一点,但是了解不同的Protocol Buffer格式如何影响编码消息的大小会非常有用. 一条简单的信息 ...
- python logging 重定向print(标准输入输出)
重定向print输出到Mongo celery 本身用到logging.info 会输出 是celery的问题,还是logging初始化的时候就会有输出? 好像是celery 配合logging的问题 ...
- vue的组件名称问题
如果组件名称中带有大写字母,那么会报错
- Linux https认证原理
HTTPS在传输的过程中会涉及到三个密钥:服务器端的公钥和私钥,用来进行非对称加密客户端生成的随机密钥,用来进行对称加密一个HTTPS请求实际上包含了两次HTTP传输,可以细分为8步.1.客户端向服务 ...
- YAML_08 handlers触发器
ansible]# vim adhttp.yml --- - hosts: cache remote_user: root tasks: - copy: src: /r ...