I developed a project using RestController in Spring Boot and it worked without error.
Now I use AWS lambda but I get a null pointer exception when I try to inject a Spring bean to the the lambda handler:
public class HelloWorldHandler implements RequestHandler<Map<String, Object>, Object> {
@Autowired
private IUserService userservice;
public Object handleRequest(Map<String, Object> input, final Context context) {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
User testUser = new User();
testUser.setId("10");
testUser.setLastname("test_lastname");
testUser.setMail("test@al.com");
userservice.addUser(testUser);
return new GatewayResponse("success", headers, 200);
}
}
Exception:
{
"errorMessage": "java.lang.NullPointerException",
"errorType": "java.lang.NullPointerException",
"stackTrace": [
"HelloWorldHandler.handleRequest(HelloWorldHandler.java:30)",
"HelloWorldHandler.handleRequest(HelloWorldHandler.java:21)"
]
}