Angular 到 Spring 启动微服务连接错误

Angular to Spring Boot Micro services connectivity Error

我正在尝试从我的 Angular 应用程序连接到构建在 Spring 引导和 Spring 云上的后端 micro-services。 UI 通过 Zuul 调用微服务层,Zuul 路由到相应的微服务

在浏览器控制台中从 angular UI 连接到微服务时出现以下错误:

加载失败:https://microservice url - 预检响应中 Access-Control-Allow-Headers 不允许请求 header 字段 Access-Control-Allow-Origin。

谁能解释一下这个错误指的是什么?

我在实现接口过滤器时遇到了同样的问题

然后允许 Access-Control-Allow-Headers 和 Access-Control-Expose-Headers 添加 CORS 问题

@Component
public class CORSFilter implements Filter{


 @Override
        public void doFilter(ServletRequest request, ServletResponse res, FilterChain chain) throws IOException, ServletException {
            HttpServletResponse response = (HttpServletResponse) res;
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");


            response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
            response.setHeader("Access-Control-Expose-Headers", "Content-Type, Access-Control-Expose-Headers, Authorization, X-Requested-With");
            chain.doFilter(request, response);
            logger.info(request.getRemoteAddr());
        }

}