当前位置:网站首页>How to implement cross domain requests
How to implement cross domain requests
2022-07-04 06:02:00 【Daily enlightenment】
Method 1 :
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig(){
CorsConfiguration configuration = new CorsConfiguration();
// Set properties
// Addresses that allow cross domain requests ,* Express all
configuration.addAllowedOrigin("*");
// Configure cross domain request headers
configuration.addAllowedHeader("*");
// Configure cross domain request methods
configuration.addAllowedMethod("*");
// Indicates whether the same is used for cross domain requests session
configuration.setAllowCredentials(true);
return configuration;
}
@Bean
public CorsFilter corsFilter(){
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**",buildConfig());
return new CorsFilter(source);
}
}
Method 2 :
@CrossOrigin(origins = "*",allowedHeaders = "*",methods = {},allowCredentials = "true")
@RestController
@CrossOrigin(origins = "*",allowedHeaders = "*",methods = {},allowCredentials = "true")
public class TestController {
@RequestMapping("/auth/login")
public String test(){
System.out.println("test");
return "";
}
}
边栏推荐
猜你喜欢
Online shrimp music will be closed in January next year. Netizens call No
High performance parallel programming and optimization | lesson 02 homework at home
冲击继电器JC-7/11/DC110V
【微服务】Nacos集群搭建以及加载文件配置
buuctf-pwn write-ups (8)
QT qtablewidget table column top requirements ideas and codes
Webrtc quickly set up video call and video conference
Leetcode question brushing record | 206_ Reverse linked list
A little understanding of GSLB (global server load balance) technology
Halcon image calibration enables subsequent image processing to become the same as the template image
随机推荐
如何获取el-tree中所有节点的父节点
Descriptive analysis of data distribution characteristics (data exploration)
Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
left_and_right_net正常版本
Detectron: train your own data set -- convert your own data format to coco format
How to get the parent node of all nodes in El tree
Compound nonlinear feedback control (2)
BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
[untitled]
如何判断数组中是否含有某个元素
19. Framebuffer application programming
Actual cases and optimization solutions of cloud native architecture
Take you to quickly learn how to use qsort and simulate qsort
MySQL的information_schema数据库
QT 获取随机颜色值设置label背景色 代码
安装 Pytorch geometric
BUU-Crypto-[GXYCTF2019]CheckIn
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
My NVIDIA developer journey - optimizing graphics card performance
Programmers don't talk about morality, and use multithreading for Heisi's girlfriend