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?
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
}
thanks in advance!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With