Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What does Spring AOT processing do, and how does it relate to native images?

Spring AOT processing runs at build time: it starts the application context in a special mode, evaluates which beans exist and how they are wired, and generates Java source code that registers those bean definitions directly, plus the runtime hints (reflection, proxies, resources) a native image needs. This removes the reflection-heavy configuration parsing that GraalVM could not follow. Conditions such as @Profile and @ConditionalOnProperty are evaluated during the build, so the bean set is fixed. Build plugins run it in the processAot (Gradle) or process-aot (Maven) step, and the generated code can also run on the JVM with -Dspring.aot.enabled=true for faster startup.

Why this question is asked

Spring's flexibility comes from doing a lot of work at startup: scanning classes, reading annotations, evaluating conditions and creating proxies, much of it through reflection. That is exactly what a GraalVM native image cannot handle without help, and it is also a large part of a Spring Boot application's startup time. Spring AOT is the bridge. Interviewers ask about it to see whether we understand what changes when we build ahead of time and why some Spring features behave differently afterwards. In this answer, we will recap what Spring does at startup, see what AOT generates and when, understand why conditions are fixed at build time, and see how AOT relates to native images and to the JVM.

1A Quick Recap of What Spring Does at Startup

When a Spring Boot application starts on the JVM, the framework scans packages for components, parses @Configuration classes, reads @Bean methods, evaluates conditions such as @ConditionalOnClass and @ConditionalOnProperty from auto-configuration, works out which constructor to call for each bean, and finally creates the beans, many of them through reflection. Most of this is the same on every start of the same jar in the same environment, yet it is repeated every time.

For a native image this is worse than slow. GraalVM's static analysis cannot follow reflection driven by annotations it does not understand, so a native image built from plain Spring would be missing classes and constructors all over the place.

2What AOT Processing Generates

Spring AOT runs during the build, after compilation. It creates the application context in a special refresh mode that evaluates bean definitions but does not create the beans themselves. With the resulting picture of the context, it generates Java source files that, at run time, register each bean definition directly with plain Java code: which class, which constructor or factory method, which dependencies. It also writes runtime hints, the metadata a native image needs, for everything it saw would be accessed reflectively, such as configuration properties classes and proxied interfaces.

Java
// Generated by Spring AOT (simplified); Maven: target/spring-aot/main/sources
// Gradle: build/generated/aotSources
public class OrderService__BeanDefinitions {
public static BeanDefinition getOrderServiceBeanDefinition() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(OrderService.class);
beanDefinition.setInstanceSupplier(getOrderServiceInstanceSupplier());
return beanDefinition;
}
private static BeanInstanceSupplier<OrderService> getOrderServiceInstanceSupplier() {
return BeanInstanceSupplier.<OrderService>forConstructor(OrderRepository.class)
.withGenerator((registeredBean, args) -> new OrderService(args.get(0))); // plain new, no reflection
}
}
Step throughWhere AOT sits in the build
  1. Compilejavac produces classes
  2. Spring AOT (processAot / process-aot)evaluate context, generate sources and hints
  3. Compile generated sourcesbean registration code
  4. Package jarapp plus generated code and hints
  5. Optional: native-imageuses generated code and hints

5 layers, from the top down. Step through them one at a time.

Notice the last line: the bean is created with a normal constructor call, which both the native-image analysis and the JIT can see. Classpath scanning and condition evaluation have already happened; their result is baked into the generated code.

3Why Conditions Are Fixed at Build Time

Because AOT records the outcome of evaluating the context, every condition that decides whether a bean exists is evaluated during the build, using the configuration available then. @Profile, @ConditionalOnProperty, @ConditionalOnBean and the rest are all decided once. At run time, the generated code simply registers the beans that were chosen; it does not re-evaluate the conditions.

So the bean set is fixed. If a bean is annotated with @Profile("cloud") and the build ran without that profile, the bean is not part of the generated context and activating the profile at run time will not create it. Property values are still bound at run time, so a @Value or @ConfigurationProperties field can change per environment; only the choice of which beans exist is frozen.

Java
@Bean
@ConditionalOnProperty(name = "payments.mode", havingValue = "stripe")
PaymentGateway stripeGateway() { return new StripeGateway(); }
// Build with AOT, without payments.mode set:
// java -Dspring.aot.enabled=true -jar app.jar --payments.mode=stripe
// -> stripeGateway bean is not created; the condition was decided at build time

4How It Relates to Native Images and the JVM

For native images, AOT is required. The native build first runs Spring AOT and then passes the application, including the generated sources and hints, to native-image. Without the generated code and hints, the native image would not work.

On the JVM, AOT is optional. A jar built with AOT processing contains the generated code, but Spring uses it only when started with -Dspring.aot.enabled=true; otherwise it does the usual startup work. Using it saves the scanning and condition evaluation, which typically trims startup by a modest amount, often 10 to 20 percent, and combines well with class data sharing or the JDK AOT cache. The build plugins run it as processAot in Gradle, when the native build tools plugin or the org.springframework.boot.aot plugin is applied, and as the process-aot goal of the Spring Boot Maven plugin, which the native profile enables.

XML
<!-- Maven: AOT on the JVM, without the native profile -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution><id>process-aot</id><goals><goal>process-aot</goal></goals></execution>
</executions>
</plugin>
$ java -Dspring.aot.enabled=true -jar target/orders.jar
... Starting AOT-processed OrdersApplication ...
... Started OrdersApplication in 1.92 seconds # against 2.31 seconds without AOT

The exact gain depends on the application; measure it for each service.

5Follow-up questions

Does AOT make the application run faster after startup?

Not noticeably. It mainly removes startup work: scanning, parsing and condition evaluation. Once the beans exist, the application runs the same code as before. The bigger run-time effects come from the native image itself, not from AOT on the JVM.

Can I use a runtime profile with AOT at all?

Profiles still work for property values, because property files for the active profile are read at run time. What does not change is which beans exist. If beans must differ per environment, we build with the right profile, build separate artifacts, or move the choice into runtime logic inside a bean.

What happens if code relies on @ConditionalOnBean or other conditions that depend on the environment?

They are all evaluated at build time with the build's environment. The generated context reflects that one evaluation. Any condition whose answer depends on the deployment environment needs to become a runtime decision.

6Conclusion

In this answer, we saw that Spring AOT evaluates the application context at build time and generates Java code that registers the bean definitions directly, plus the runtime hints a native image needs. This replaces reflection-heavy startup work, which is required for native images and optional on the JVM through -Dspring.aot.enabled=true. Because conditions such as @Profile and @ConditionalOnProperty are evaluated during the build, the bean set is fixed, while property values are still bound at run time.

What to say in the interviewAbout 80 seconds aloud

Open with

Spring AOT is a build-time step that does part of Spring's startup work in advance. After compilation, the build plugin, processAot in Gradle or process-aot in Maven, refreshes the application context in a special mode that works out all the bean definitions without creating beans.

Then, if they want more

From that it generates Java source code that registers each bean directly, with plain constructor calls instead of reflection, and it writes runtime hints for reflection, proxies and resources. For native images this is essential, because GraalVM's static analysis can't follow Spring's annotation-driven reflection, so the native build runs AOT first and native-image uses the generated code and hints.

The important consequence is that conditions are evaluated at build time: @Profile, @ConditionalOnProperty and similar decide once, during the build, which beans exist, and that bean set is fixed. Setting a property or profile at runtime won't add or remove beans, although property values are still bound at runtime.

The same generated code can also be used on the JVM by starting with -Dspring.aot.enabled=true, which skips classpath scanning and condition evaluation and trims startup somewhat, especially combined with CDS or the JDK AOT cache.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does Spring AOT processing do, and how does it relate to native images?": https://scrivio-interview-library.netlify.app/spring-boot/native-and-aot/252bf2e2de/