在我的 Controller 类中,我指定了@CrossOrigin(origins = "*")
,我正在尝试连接我的角度应用程序,但它不起作用。我知道这是因为 Angular 在 4200 端口上运行,而 Java 应用程序在 8080 端口上运行,但是有什么方法可以做到这一点吗?不部署 war ?
@CrossOrigin(origins = "*")
@RestController
public class UserController {
//
}
最佳答案
- 如果您使用 Spring boot
CORS support is disabled by default and is only enabled once the management.endpoints.web.cors.allowed-origins property has been set.
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.
关于java - @CrossOrigin(origins = "*") 在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56404928/