java – amazon aws lamba函数与spring autowired依赖项

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

这是我的代码,它具有空的自动装配字段,但在其他情况下工作正常(如果我用new替换autowired:

@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上的这个项目为我正在尝试做的工作提供了一个模板:

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

点赞