Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

Your platform team wants to run Spring AOT processing on the JVM (not native) for all services to reduce startup time. What constraints does this impose on service teams, and how would you roll it out?

Running Spring AOT on the JVM fixes the bean definitions at build time, so service teams can no longer rely on run-time profiles or properties to decide which beans exist; those choices must move into runtime logic or into separate builds. Turning it on means running the build plugin's AOT step and starting with -Dspring.aot.enabled=true, and because the gain varies, we measure it per service and combine AOT with CDS or the JDK AOT cache for a larger effect. I would roll it out as an opt-in flag in the golden path, then make it the default once a set of services has proved compatible.

Why this question is asked

Platform teams like Spring AOT on the JVM because it promises shorter startup without the cost and risk of native images. But it changes a rule that many Spring applications quietly depend on: that the same jar can choose different beans in different environments. Interviewers ask this scenario to see whether we can name the constraint precisely, estimate the real gain and roll out a platform change without breaking services. In this answer, we will recap what AOT changes, list the constraints it puts on service teams and how they adapt, look at the gain and how to multiply it with class data sharing or the JDK AOT cache, and plan a staged rollout.

1A Quick Recap of AOT on the JVM

Spring AOT processing runs during the build. It evaluates the application context without creating beans, then generates Java code that registers exactly the resulting bean definitions, plus runtime hints. On the JVM, this generated code is only used when the application starts with the system property spring.aot.enabled set to true. In that mode Spring skips classpath scanning, configuration class parsing and condition evaluation, which saves part of the startup time, typically 10 to 20 percent of the Spring part of startup; check it for each service.

2The Constraint: Beans Are Chosen at Build Time

Because the bean definitions are generated once, conditions are evaluated with the build's configuration and never again. @Profile on beans, @ConditionalOnProperty, @ConditionalOnBean and the decisions inside auto-configuration are all frozen. A service built once and deployed to dev, staging and prod with a different profile in each, choosing for example an in-memory cache in dev and Redis in prod, will get the same beans everywhere: those chosen during the build.

Two other build-time assumptions come with it: the classpath must be the same at build time and run time, and bean definitions should be declared with precise types, since the generated code works from the information it had. Property values are not affected: @Value and @ConfigurationProperties are bound at run time, and profile-specific property files are still read.

YAML
# Same jar, two environments, AOT enabled at run time
$ java -Dspring.aot.enabled=true -Dspring.profiles.active=dev -jar orders.jar
# cache bean: RedisCacheManager (chosen at build time with the prod profile)
$ java -Dspring.aot.enabled=true -Dspring.profiles.active=prod -jar orders.jar
# cache bean: RedisCacheManager
# spring.datasource.url: different in each, because values are still bound at run time

3How Service Teams Adapt

Teams that select beans by environment have three options. First, move the choice into runtime logic: register one bean that reads a property and behaves accordingly, for example a cache bean whose type is chosen from cache.mode inside a factory. Second, make the difference a configuration value rather than a different bean: point the same Redis client at a local Redis in dev instead of swapping to an in-memory implementation. Third, if the difference is structural, build separate artifacts with AOT run under each profile, at the cost of more builds.

The platform team helps by publishing a checker. A simple build step can search for @Profile and @ConditionalOnProperty on application beans and flag them for review, and an integration test that starts the AOT-processed application with each environment's configuration and compares the bean names against the plain JVM start catches anything the search misses.

Common patterns and their AOT-friendly form
TodayProblem under AOTChange to
@Profile("dev") in-memory cachebean set frozenone cache bean, mode from property
@ConditionalOnProperty feature beanflag ignored at run timebean always present, checks flag
Different datasource URLs per envnonekeep: values bound at run time
Prod-only bean with extra librariesstructural differenceseparate artifact built with profile

4Turning It On and Measuring the Gain

Enabling it needs two things: the build must run the AOT step (the process-aot goal of the Spring Boot Maven plugin, or the org.springframework.boot.aot Gradle plugin, which adds processAot), and the runtime must pass -Dspring.aot.enabled=true, for example through JAVA_TOOL_OPTIONS in the shared Helm chart. We measure startup time before and after on each service, because the gain depends on how much scanning and condition work the application had.

For a bigger gain we combine it with JVM-level startup features. Class data sharing stores pre-parsed class metadata in an archive created by a training run, and from JDK 24 the AOT cache (JEP 483, with later JEPs adding method profiles) stores loaded and linked classes as well. These attack class loading, which AOT does not touch, so the effects add up.

Java
# 1. Build with AOT (Maven) and extract the jar for efficient class loading
$ mvn package # process-aot goal configured
$ java -Djarmode=tools -jar target/orders.jar extract --destination app
# 2. Training run that creates the JDK AOT cache (JDK 25 one-step form)
$ java -XX:AOTCacheOutput=app.aot -Dspring.aot.enabled=true \
-Dspring.context.exit=onRefresh -jar app/orders.jar
# 3. Production start
$ java -XX:AOTCache=app.aot -Dspring.aot.enabled=true -jar app/orders.jar
# baseline 3.9 s -> AOT 3.3 s -> AOT + AOT cache 1.7 s (example numbers)

Notice the training run uses spring.context.exit=onRefresh, which starts the context and then exits, so the cache captures startup classes without serving traffic.

5Rolling It Out

We roll out in stages. First, an opt-in flag in the golden path chart and build template, so any team can switch it on with one line and get the measurement automatically. Early adopters are services with no environment-specific beans and a real need for startup speed, such as those that autoscale often. Their results and fixes become the documentation. Once a meaningful set of services, say 20 across different kinds, runs with it for a few weeks without incidents, it becomes the default for new services, and existing services follow as the checker shows them compatible. A per-service opt-out remains for services where the gain is too small to justify changes.

Step throughStaged rollout of AOT on the JVM
  1. Opt-in flag in golden pathbuild step + runtime property
  2. Checker finds profile-based beans?
    YesTeam moves choice to runtime logicNoEnable and measure startup
  3. Early adopters run for weeksstartup gain, incidents
  4. Enough services proven?
    YesDefault on, opt-out allowedNoKeep opt-in, fix gaps

4 steps in order. Play them, or step through them one at a time.

6Follow-up questions

What is the risk if a team enables AOT without checking?

The service starts, but with the bean set chosen at build time. A dev-only bean may appear in production, or a production bean may be missing, without any error. That is why the checker and a bean-comparison test are part of the rollout.

Is the gain from AOT on the JVM worth it on its own?

Sometimes not. It removes Spring's scanning and condition work but not class loading or JIT warmup. On its own it often saves a few hundred milliseconds; combined with CDS or the JDK AOT cache, the total gain can be much larger, so we present them as one package.

Do tests run with AOT too?

Spring can process test contexts ahead of time as well (processTestAot), which is mainly used for native tests. For the JVM rollout, an integration test that starts the AOT-processed jar with real configuration is the important one.

7Conclusion

In this answer, we saw that Spring AOT on the JVM fixes bean definitions at build time, so services that choose beans by profile or property per environment must move that choice into runtime logic or build separate artifacts, while property values keep working. We enabled it with the build's AOT step and -Dspring.aot.enabled=true, measured the gain per service and combined it with CDS or the JDK AOT cache, and rolled it out as an opt-in golden path flag before making it the default.

What to say in the interviewAbout 90 seconds aloud

Open with

The main constraint is that AOT freezes the bean definitions at build time. Conditions like @Profile and @ConditionalOnProperty are evaluated once in the build, so a service that builds one jar and picks different beans per environment through a runtime profile will get the build-time choice everywhere, without any error.

Then, if they want more

Property values are still bound at runtime, so URLs and timeouts are fine. Teams that select beans per environment have to move that choice into runtime logic, for example one bean that reads a property, or turn the difference into a configuration value, or build separate artifacts if it is really structural.

To enable it, the build runs the AOT step, process-aot in Maven or processAot in Gradle, and the runtime adds -Dspring.aot.enabled=true. I'd measure startup per service, because the gain varies and alone it's often modest, and I'd combine it with CDS or the JDK AOT cache from JDK 24 and later, which tackle class loading, for a much bigger effect.

For rollout, I'd add it as an opt-in flag in the golden path with a checker that flags profile-based beans and a test comparing bean names.

Early adopters prove it out, and once enough services have run with it for a few weeks, it becomes the default for new services, with an opt-out kept for services where the gain is too small.

About this answer

Last updated
12 November 2026
Versions it names
Java 24, Java 25
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 "Your platform team wants to run Spring AOT processing on the JVM (not native) for all...": https://scrivio-interview-library.netlify.app/spring-boot/native-and-aot/851e971b06/