You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仅部署环境出现Spring Boot CORS错误问题求助

问题描述

我通过以下方式配置CORS:

@Bean
public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedOrigins("http://localhost:4200", "http://localhost:4201", "http://<ip_address>");
            }
        };
    }

注:此处<ip_address>为已部署Angular应用的真实可用IP地址

当前场景

  • 服务1(使用Spring Security):上述配置在本地和部署环境均正常工作。
  • 服务2(未使用Spring Security):上述配置在本地正常,但部署环境下出现CORS错误。

内容的提问来源于stack exchange,提问作者Abhi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 00:22:01