重写WebMvcConfigurer实现全局跨域配置

This commit is contained in:
fuce1314 2023-05-03 18:37:22 +08:00
parent 5e863c719c
commit 0171846584
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package cn.com.v2.common.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//重写WebMvcConfigurer实现全局跨域配置
@Configuration
public class CorsConfig implements WebMvcConfigurer{
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
// 是否发送Cookie
.allowCredentials(true)
// 放行哪些原始域
.allowedOrigins("*")
// 放行哪些请求方式
.allowedMethods("GET", "POST", "PUT", "DELETE")
// 放行哪些原始请求头部信息
.allowedHeaders("*")
// 暴露哪些头部信息
.exposedHeaders("*");
}
}