当在Amazon AWS Lambda中执行代码时,我的@autowired spring依赖项为null。如果没有上下文被加载是有意义的,但是我认为SpringBeanAutowiringSupport会有所帮助。如何在Amazon Lambda中正确注入依赖项?
这是我的代码,具有空的自动装配字段,但否则工作正常(如果我将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上的这个项目为我正在尝试做的工作提供了一个模板,可以正常工作:
https://github.com/cagataygurturk/aws-lambda-java-boilerplate
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句