Skip to content

Spring AotInitializerNotFoundException with AOT #1580

@andreaabram-eutelsat

Description

@andreaabram-eutelsat

Dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>3.5.7</version>
</dependency>
<dependency>
    <groupId>com.amazonaws.serverless</groupId>
    <artifactId>aws-serverless-java-container-springboot3</artifactId>
    <version>2.1.5</version>
</dependency>

Handler

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 more

Spring Code:

The deduceMainApplicationClass method use the StackWalker to find, in the stacktrace, the first method that has a static main.
It finds the AWS Runtime Interface Client class: com.amazonaws.services.lambda.runtime.api.client.AWSLambda so AOT looks for the wrong *__ApplicationContextInitializer
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions