spring-boot - AWS Lambda - Spring Boot 未处理请求
问题描述
我正在尝试在 AWS lambda 中将 Spring Boot 应用程序作为无服务器运行,并且在调用 lambda 函数时遇到异常。Spring Boot 应用程序成功运行,但似乎无法映射请求
2018-09-25 06:11:50.717 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-09-25 06:11:50.823 INFO 1 --- [ main] **my.service.Application : Started Application in 7.405 seconds (JVM running for 8.939)**
START RequestId: decfc13c-c089-11e8-bacd-a37f1ba65629 Version: $LATEST
2018-09-25 06:11:50.994 ERROR 1 --- [ main] **c.a.s.p.i.s.AwsProxyHttpServletRequest : Called set character encoding to UTF-8 on a request without a content type. Character encoding will not be set
2018-09-25 06:11:51.175 ERROR 1 --- [ main] o.s.boot.web.support.ErrorPageFilter : Forwarding to error page from request [/] due to exception [null]**
java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.getRemoteAddr(AwsProxyHttpServletRequest.java:575) ~[task/:na]
at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1075) ~[task/:na]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[task/:na]
.........
2018-09-25 06:11:51.535 ERROR 1 --- [ main] s.p.i.s.AwsLambdaServletContainerHandler : Could not forward request
这是我的 StreamLambdaHandler java 文件。
public class StreamLambdaHandler implements RequestStreamHandler {
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
} catch (ContainerInitializationException e) {
throw new RuntimeException("Could not initialize Spring Boot application", e);
}
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
outputStream.close();
}
}
解决方案
看起来您可能会点击https://github.com/awslabs/aws-serverless-java-container/issues/172。根据票证,该修复程序将作为即将发布的 1.2 版本的一部分提供。
推荐阅读
- r - 如何在一张图中绘制多条 ecdf 线
- c# - 为什么反转方法调用顺序也会反转执行时间?
- c++ - 类模板的友元函数是否应该成为所有实例化的友元?
- security - 为什么在 JWT Token 中包含 Header 和 Payload?
- python - 我应该如何根据 Tkinter 中的变量更改图像
- reactjs - 如何在 React Native 中移除 Touchable Opacity 组件之间的空格
- node.js - 如何通过控制台登录 Sail.js 以获取访问路线或页眉输出?
- java - 删除旁边但出站的项目
- javascript - 在 MySQL 中使用 Javascript 更改状态
- java - 如何在 Spring Boot 中对 POST 、 PUT 、 DELETE 执行不同的验证