spzx/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java

22 lines
784 B
Java
Raw Normal View History

2024-03-22 21:19:38 +08:00
package com.atguigu.config;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Component
public class WebMvcConfiguration implements WebMvcConfigurer {
/**
* * 解决跨域
*
* @param registry 跨域注册表
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")// 添加路径规则
.allowCredentials(true)// 是否允许在跨域的情况下传递Cookie
.allowedOriginPatterns("*")// 允许请求来源的域规则
.allowedMethods("*")
.allowedHeaders("*");// 允许所有的请求头
}
}