解决springcloud gateway网关跨域的问题
在配置文件里添加配置
spring:
gateway:
globalcors:
cors-configurations:
'[/**]': # 匹配所有请求
allowedOrigins: "*" # 跨域处理 允许所有的域
allowed-headers: "*" #跨域设置
allowedMethods: # 支持的方法
- GET
- POST
- PUT
- DELETE
- OPTIONS
springboot解决跨域的问题
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CrosConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedHeaders("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.maxAge(3600);
}
}