【问题标题】:@CrossOrigin(origins = "*") is not working in firefox@CrossOrigin(origins = "*") 在 Firefox 中不起作用
【发布时间】:2023-03-26 14:32:01
【问题描述】:

在我的控制器类中,我指定了 @CrossOrigin(origins = "*"),我正在尝试连接我的 Angular 应用程序,但它无法正常工作。我知道这是因为 Angular 在 4200 端口上运行,而 Java 应用程序在 8080 端口上运行,但有什么办法吗?不展开战争?

@CrossOrigin(origins = "*")
@RestController
public class UserController {
//
}

【问题讨论】:

  • 没有部署战是什么意思?你说它在 Firefox 上不工作,这在其他导航器上工作吗?
  • 您在 Firefox Web 控制台中遇到什么错误?

标签: java eclipse spring-mvc


【解决方案1】:
  1. 如果您使用的是Spring boot

CORS 支持默认是禁用的,只有在 management.endpoints.web.cors.allowed-origins 属性已设置。

  1. 也根据CORS support in Spring Framework

如果您使用 Spring Security,请确保在 Spring 中启用 CORS 安全级别以及允许它利用配置 在 Spring MVC 级别定义。

  1. 还有一个问题可能是CORSMIssingAllowCredentials

如果使用 XMLHttpRequest 发出请求,请确保您是 没有将 withCredentials 设置为 true。

  1. 火狐Does not support CORS for resources which redirect

【讨论】:

    猜你喜欢
    • 2021-11-19
    • 2020-10-09
    • 2019-09-18
    • 2020-08-26
    • 2012-11-27
    • 2012-02-27
    • 2017-02-08
    • 2014-08-23
    • 2013-07-12
    相关资源
    最近更新 更多