server: port: 9002 spring: application: name: gateWay-server profiles: active: dev # cloud: # gateway: # globalcors: # 全局 CORS 配置 # cors-configurations: # '[/**]': # 对所有路径应用此 CORS 配置 # # --- 修改这里 --- # # 将 "*" 改回具体的开发环境地址模式 # allowedOriginPatterns: # - "http://localhost:*" # 允许来自 http://localhost 的任意端口 # - "http://127.0.0.1:*" # 允许来自 http://127.0.0.1 的任意端口 # # --- ↑↑↑ 关键修改 ↑↑↑ --- # # 如果你的前端运行在特定端口,例如 8080,也可以用更精确的 (但上面的模式更灵活): # # allowedOrigins: "http://localhost:8080" # 注意这里用 allowedOrigins # # allowedMethods: # - "GET" # - "POST" # - "PUT" # - "DELETE" # - "OPTIONS" # allowedHeaders: "*" # allowCredentials: true # 保留 true,因为你需要凭证 # maxAge: 360000 # ## --- 仍然重要的提醒 --- ## 检查是否使用了 Spring Security。如果使用了,强烈建议将 CORS 配置 ## 统一放在 Spring Security 的配置中,并移除或注释掉这里的 globalcors 部分, ## 以避免配置冲突。 ## --- logging: config: classpath:log4j2.xml