当前位置:网站首页>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 "";
}
}边栏推荐
- Functions in C language (detailed explanation)
- Leetcode question brushing record | 206_ Reverse linked list
- A little understanding of GSLB (global server load balance) technology
- How to avoid JVM memory leakage?
- Understanding of cross domain and how to solve cross domain problems
- 1480. Dynamic sum of one-dimensional array
- 实用的小工具指令
- JS execution mechanism
- Actual cases and optimization solutions of cloud native architecture
- fastjson
猜你喜欢

JS flattened array of number shape structure

检漏继电器JY82-2P

体验碎周报第 102 期(2022.7.4)

Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor

实用的小工具指令

How to configure static IP for Kali virtual machine
![BUU-Real-[PHP]XXE](/img/97/b7139270145e6aa6a4f5d1067e2527.jpg)
BUU-Real-[PHP]XXE

Programmers don't talk about morality, and use multithreading for Heisi's girlfriend

JSON Web Token----JWT和傳統session登錄認證對比

BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
随机推荐
left_ and_ right_ Net normal version
BUU-Reverse-easyre
How to realize multi account login of video platform members
Detailed explanation of common APIs for component and container containers: frame, panel, scrollpane
left_and_right_net正常版本
Weekly summary (*63): about positive energy
Input displays the currently selected picture
Gridview出现滚动条,组件冲突,如何解决
webrtc 快速搭建 视频通话 视频会议
ES6 modularization
Thinkphp6.0 middleware with limited access frequency think throttle
"In simple language programming competition (basic)" part 1 Introduction to language Chapter 3 branch structure programming
C语言中的函数(详解)
实用的小工具指令
Experience weekly report no. 102 (July 4, 2022)
High performance parallel programming and optimization | lesson 02 homework at home
left_and_right_net可解释性设计
HMS v1.0 appointment. PHP editid parameter SQL injection vulnerability (cve-2022-25491)
The difference between PX EM rem
Basic concept of bus