java - @CrossOrigin(origins = "*") 在 Firefox 中不起作用

标签 java eclipse spring-mvc

在我的 Controller 类中,我指定了@CrossOrigin(origins = "*"),我正在尝试连接我的角度应用程序,但它不起作用。我知道这是因为 Angular 在 4200 端口上运行,而 Java 应用程序在 8080 端口上运行,但是有什么方法可以做到这一点吗?不部署 war ?

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

最佳答案

  1. 如果您使用 Spring boot

CORS support is disabled by default and is only enabled once the management.endpoints.web.cors.allowed-origins property has been set.

  • 同时根据CORS support in Spring Framework
  • If you are using Spring Security, make sure to enable CORS at Spring Security level as well to allow it to leverage the configuration defined at Spring MVC level.

  • 还有一个问题可能是 CORSMIssingAllowCredentials
  • If the request is being issued using XMLHttpRequest, make sure you're not setting withCredentials to true.

  • 火狐 Does not support CORS for resources which redirect
  • 关于java - @CrossOrigin(origins = "*") 在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56404928/

    相关文章:

    Java Enum 数据长值被设置为零

    java - 从 Eclipse(或 IntelliJ IDEA)远程执行/调试 Java 代码

    java - 将 zip 文件导入为库 - Eclipse Java

    java - 静态 block 不适用于 Spring 中的@Value

    java - 如何创建 @RequestMapping @PathVariable 以在参数中包含/?

    java - 在格式错误的 HTML 中按类型获取元素

    java - 隐藏 Android 操作栏?

    java - yyyy-MM-dd'T'HH :mm:ss. SSSSSSS'Z' 格式

    java - 服务器运行java servlet

    java - Spring MVC 重定向是在 url 中添加一些参数