AWS lambda中的春季功能未寄回状态代码

发布于 2025-01-27 21:27:11 字数 469 浏览 4 评论 0原文

我有以下代码工作并返回状态代码。

        final APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
        responseEvent.setHeaders(Map.of(CONTENT_TYPE, APPLICATION_JSON));
        responseEvent.setBody(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
        responseEvent.setStatusCode(200);

但是,我最近将Spring功能适配器更新为3.2.3,并且不再在响应中收到状态代码。实际上,反应现在只是身体。

我的设置是AWS lambda,使用弹簧功能,在API网关后面。

I had the following code working and returning a statusCode.

        final APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
        responseEvent.setHeaders(Map.of(CONTENT_TYPE, APPLICATION_JSON));
        responseEvent.setBody(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
        responseEvent.setStatusCode(200);

However i have recently updated the spring function adapter to 3.2.3, and i no longer recieve the status code in the response. In fact the response is now just the body.

My setup is aws lambda using spring function, behind api gateway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的軌跡 2025-02-03 21:27:11

这有效。

final APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
        final Map<String, Object> headers = new HashMap<>();
        headers.put(CONTENT_TYPE, APPLICATION_JSON);
        final ObjectMapper objectMapper = new ObjectMapper();
  responseEvent.setBody(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
            responseEvent.setStatusCode(HttpStatus.OK.value());
        Message<APIGatewayProxyResponseEvent> finalResponse = new GenericMessage<>(responseEvent, headers);

this works.

final APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
        final Map<String, Object> headers = new HashMap<>();
        headers.put(CONTENT_TYPE, APPLICATION_JSON);
        final ObjectMapper objectMapper = new ObjectMapper();
  responseEvent.setBody(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
            responseEvent.setStatusCode(HttpStatus.OK.value());
        Message<APIGatewayProxyResponseEvent> finalResponse = new GenericMessage<>(responseEvent, headers);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文