带弹簧自动关联功能的AWS Lambda函数 [英] aws lambda function with spring autowired dependencies

查看:97
本文介绍了带弹簧自动关联功能的AWS Lambda函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Amazon AWS Lambda中执行代码时,我的@autowired spring依赖项为null.如果没有上下文正在加载是有道理的,但我认为SpringBeanAutowiringSupport会有所帮助.如何在Amazon Lambda中正确注入依赖项?

when code is executed in amazon aws lambda, my @autowired spring dependencies are null. Makes sense if there is no context being loaded, but i thought SpringBeanAutowiringSupport would help. How do you inject dependencies correctly in amazon lambda?

这是我的代码,其中具有自动接线的字段为空,但可以正常工作(如果我用new替换自动接线:

This is my code that has null autowired fields but otherwise works fine (if i replace autowired with new:

@Component
public class ApplicationEventHandler {

@Autowired
private Foo foo;


         public ApplicationEventHandler() {
             logger.info("I'm sure the constructor is being called");
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
             //doesn't seem to help
         }

         public void deliveryFailedPermanentlyHandler(SNSEvent event, Context context) throws IOException {
             foo.doStuff() // causes NPE

         }

提前谢谢!

推荐答案

在github上的该项目为我试图做的工作提供了一个很好的模板:

this project on github provides a template for what i'm trying to do which works fine:

https://github.com/cagataygurturk/aws-lambda-java-boilerplate

这篇关于带弹簧自动关联功能的AWS Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆