Repository navigation
NPE on org.springframework.boot.SpringApplication.getMainApplicationClass() with AOT #1579
Description
Activity
andreaabram-eutelsat commented
on Nov 11, 2025 AuthorMore actionsI think that the issue is in the async initialization logic of the
SpringDelegatingLambdaContainerHandlerHere:
Lines 52 to 63 in 4696691
public SpringDelegatingLambdaContainerHandler(final Class<?>... startupClasses) throws ContainerInitializationException { SpringDelegatingInitHandler initHandler = new SpringDelegatingInitHandler(startupClasses); if (InitializationTypeHelper.isAsyncInitializationDisabled()) { initHandler.initialize(); } else { AsyncInitializationWrapper asyncInitWrapper = new AsyncInitializationWrapper(); asyncInitWrapper.start(initHandler); } this.mvc = initHandler.getMvc(); this.mapper = new ObjectMapper(); this.responseWriter = new AwsProxyHttpServletResponseWriter(); } Also here:
Lines 73 to 90 in 4696691
private static final class SpringDelegatingInitHandler implements InitializableLambdaContainerHandler { private ServerlessMVC mvc; private final Class<?>[] startupClasses; public SpringDelegatingInitHandler(final Class<?>... startupClasses) { this.startupClasses = startupClasses; } @Override public void initialize() throws ContainerInitializationException { this.mvc = ServerlessMVC.INSTANCE(this.startupClasses); this.mvc.waitForContext(); } public ServerlessMVC getMvc() { return this.mvc; } } Spring Code:
The
deduceMainApplicationClassmethod use theStackWalkerto find, in the stacktrace, the first method that has astatic main
This method doesn't exists in the different thread

andreaabram-eutelsat commented
on Nov 11, 2025 AuthorMore actionsUpdate
Creating a custom lambda handler instead of using the
SpringDelegatingLambdaContainerHandler"bypass" this issue but creates anotherHandler:
public class StreamLambdaHandler implements RequestStreamHandler { private static final Logger logger = LoggerFactory.getLogger(StreamLambdaHandler.class); private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; static { try { handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(IssueApplication.class); } catch (ContainerInitializationException e) { // if we fail here. We re-throw the exception to force another cold start e.printStackTrace(); throw new RuntimeException("Could not initialize Spring Boot application", e); } } @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { logger.info("entered generic stream lambda handler"); handler.proxyStream(inputStream, outputStream, context); } }
Issue:
Description: Startup with AOT mode enabled failed: AOT initializer com.amazonaws.services.lambda.runtime.api.client.AWSLambda__ApplicationContextInitializer could not be found Action: Consider the following: Did you build the application with enabled AOT processing? Is the main class com.amazonaws.services.lambda.runtime.api.client.AWSLambda correct? If you want to run the application in regular mode, remove the system property 'spring.aot.enabled' Error loading class org.example.StreamLambdaHandler: java.lang.ExceptionInInitializerError java.lang.ExceptionInInitializerError at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Unknown Source) at java.base/java.lang.Class.forName(Unknown Source) Caused by: org.springframework.boot.AotInitializerNotFoundException: Startup with AOT mode enabled failed: AOT initializer com.amazonaws.services.lambda.runtime.api.client.AWSLambda__ApplicationContextInitializer could not be found at org.springframework.boot.SpringApplication.addAotGeneratedInitializerIfNecessary(SpringApplication.java:426) at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:382) at org.springframework.boot.SpringApplication.run(SpringApplication.java:317) at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149) at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.initialize(SpringBootLambdaContainerHandler.java:198) at com.amazonaws.serverless.proxy.InitializationWrapper.start(InitializationWrapper.java:35) at com.amazonaws.serverless.proxy.spring.SpringBootProxyHandlerBuilder.buildAndInitialize(SpringBootProxyHandlerBuilder.java:80) at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.getAwsProxyHandler(SpringBootLambdaContainerHandler.java:96) at org.example.StreamLambdaHandler.<clinit>(StreamLambdaHandler.java:23) ... 3 moreIt this case the
deduceMainApplicationClassfinds the AWS Runtime Interface Client class:com.amazonaws.services.lambda.runtime.api.client.AWSLambdaso AOT looks for the wrong*__ApplicationContextInitializerI created another issue about this specific problem: #1580
This is a blocking issue for me, too.
Hi!
I'm trying to implement AOT into a simple java lambda
I'm using the
com.amazonaws.serverless.proxy.spring.SpringDelegatingLambdaContainerHandlerhandlerDependencies:
Logs: