在使用了spring-cloud-starter-gateway后,为什么还会发生cors问题

java 复制代码
//1.需要配置类
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;

@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);
        return new CorsWebFilter(source);
    }
}
//2.yml文件配置
spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
      routes:
        - id: service-acl #nacos中的服务名
          uri: lb://service-acl #转发的路径
          predicates:
            - Path=/*/acl/** #断言,若路径包含acl则转发给service-acl处理
//3.将原来控制器上的@CrossOrigin注解全部去掉
相关推荐
Flynn Liang几秒前
AgentScope Java 深度解析:ReActAgent、HarnessAgent 与多智能体编排——JVM 上的自治 Agent 底座
java·大模型·架构设计·ai agent·spring ai·langchain4j·agentscope
Flynn Liang14 分钟前
上线后怎么排查 AI 调用?Spring AI Observability:token/延迟/成本埋点与全链路追踪
java·人工智能·spring·监控·可观测性·observability·springai
文丑颜不良啊17 分钟前
LeetCode1921~1940题目解析
java·leetcode
Tt有了t43 分钟前
设计模式速查
java·python·设计模式
Thomas.Sir1 小时前
第15课:SpringBoot连接池详解:HikariCP配置、调优、监控,4.x连接池新特性
java·spring boot
VimorphTech2 小时前
每批开 4 个线程,为什么限制不住 TTS 的总并发?
java·spring boot·spring
Pniubi2 小时前
Java为什么要分堆和栈
java·开发语言
杨凯凡2 小时前
Spring Boot 缓存一致性怎么保证?@Cacheable、@CacheEvict 与事务提交时机实战
java·spring boot·spring cache·后端开发·缓存一致性
小小晓.2 小时前
Qt 对话框、QLineEdit 与布局管理实战详解
开发语言·qt
炸薯条!3 小时前
博客系统测试报告
开发语言·lua