AOT processes the application context before runtime, so a native executable cannot freely add beans by changing a profile or conditional property later.
Spring AOT: profile and conditional beans become build-time decisions
Build the intended context
A parcel worker built with a profile selecting a local archive client cannot become a cloud archive worker just by changing a runtime environment variable if that variable changes which beans exist. AOT fixes the classpath and bean graph at build time. Values read by an existing bean may still be runtime configuration, but conditions that decide whether a bean exists are different. Profile selection and auto-configuration need a native-specific release test.
Separate properties from topology
Keep endpoints and timeouts as runtime values where the bean graph can remain fixed. Build separate native artifacts when two deployments genuinely need different conditional beans, or choose a design that selects behavior inside an existing bean without changing its type graph. Context refresh is not a substitute in a native image.
Check the exact image
Build with the production profile and run the resulting executable with production secrets and a staging dependency set. Check that the expected beans exist and rejected paths stay rejected. A JVM test alone does not establish the native image's build-time decisions.
Implementation sketch
@Configuration
@Profile("warehouse")
class WarehouseArchiveConfiguration {
@Bean
ArchiveClient warehouseArchiveClient() {
return new WarehouseArchiveClient();
}
}Cost and verification
AOT and native compilation add build time and artifact-specific validation. They can improve startup and memory behavior, but each build-time profile variant increases release and test work.
Common Mistakes
- Do not switch build-time conditional beans with a runtime property and expect a new graph.
- Do not infer native behavior solely from a JVM integration test.
- Do not combine a required native release path with live context refresh assumptions.
Read next
Spring native RuntimeHints: register resources reached only by name, Spring Boot profile files: bind only the selected environment override, Spring Boot auto-configuration: conditions and user-defined beans, Spring Cloud refresh: changed properties do not rebuild every dependency.
