Overview

The difference in invocation order between standard JVM mode and AOT mode can be viewed in the following tests. See also: https://github.com/spring-projects/spring-framework/pull/30724#issuecomment-1602534343.

Tests

JVM mode:

https://github.com/spring-projects/spring-framework/blob/2ccf4cab8b4b437915c297be979d2e569fc273ef/spring-context/src/test/java/org/springframework/context/annotation/InitDestroyMethodLifecycleTests.java#L123-L143

AOT mode:

https://github.com/spring-projects/spring-framework/blob/2ccf4cab8b4b437915c297be979d2e569fc273ef/spring-context/src/test/java/org/springframework/context/annotation/InitDestroyMethodLifecycleTests.java#L170-L203

Known Issues

  • InitDestroyAnnotationBeanPostProcessor.processAheadOfTime(RegisteredBean) gets invoked twice in the same AOT processing phase: once via CommonAnnotationBeanPostProcessor and once via InitDestroyAnnotationBeanPostProcessor.
  • InitializingBean and DisposableBean are treated specially even in AOT mode.

Comment From: sbrannen

Note: the expected order is documented in the Combining Lifecycle Mechanisms section of the reference manual.