當代碼在amazon aws lambda中執行時,我的@autowired spring依賴項爲null。有意義的,如果沒有上下文被加載,但我認爲SpringBeanAutowiringSupport將有所幫助。如何在amazon lambda中正確注入依賴關係?亞馬遜aws lamba函數與彈簧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
}
感謝
這裏是不涉及‘神奇’一個簡單的方法:用Spring-只是AWS Lambda表達式(https://開頭w^ww.profit4cloud.nl/blog/just-spring-enabled-aws-lambdas/) –