繁体   English   中英

调用 Eureka API 时 Angular 中的 CORS 原点错误

[英]CORS origin error in Angular while calling Eureka API

我有 Java Spring 启动应用程序,它具有 Eureka 服务器应用程序(Java 项目)和其他 Eureka 客户端应用程序(Java 项目)。 In Eureka Server Application project I have some of my Rest APIs exposing through my own Controller class and those APIs (localhost:8100/someApi) are accessible without any issue from Angular (localhost:4200) after configuring CORS setup in Spring Boot Application.

But some Rest APIs which are in library class of my Java Application are not accessible from Angular due to CORS error. 但是可以访问其他 Rest API,这些 API 在我创建的 Controller class 中定义。

这些是我试图访问的 API。 https://github.com/Netflix/eureka/wiki/Eureka-REST-operations

这些 API 在库代码中,如果我们在 pom.ml 中提及依赖项,就会添加这些 API。

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

我在尝试从 Angular 访问这些 Eureka API 时遇到 CORS 阻止错误,但通过 Postman 可以正常工作。 请帮忙。

您是否在 SpringBoot 应用程序中实现了跨源功能。 您能否通过默认添加 @CrossOrgina 注释在 controller 级别启用 corss origin 它将允许所有来源,包括所有 http 方法,或者可以添加自定义的全局配置,如下所示。

@Bean
Public WebMvcConfigurer corsConfigurer(){
return new WebMvcConfigurer(){
@Override
public void addCorsMapping(CoreRegistry registry){
registry.addMapping("/**").allowdOrgin("*");
}
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM