Search code examples
spring-bootahead-of-time-compile

Spring Boot AOT Compilation on JVM


I'm trying to implement AOT (Ahead-of-Time) compilation in my Spring Boot application running on the JVM. When I run the application with AOT enabled, I encounter the following error:

Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context.

What I've observed:

Without AOT enabled: The application runs successfully. With AOT enabled (-Dspring.aot.enabled=true): The application fails to start with the above error.

Environment:

  • Spring Boot Version: 3.3.4
  • Spring Cloud Version: 2023.0.1
  • Java Version: OpenJDK 21
  • Build Tool: Maven 3.9.7

I'm suspecting some of the dependencies(e.g. spring cloud, or spring security) are interfering the build process and ruin the aot compilation process.

What could be causing the ServletWebServerFactory bean to be missing in the application context when AOT is enabled?


Solution

  • After removing the dependency given below it worked as expected.

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
    </dependency>