Description
Running the following application prints 2 times Foo constructor
at startup while a single time as expected in regular mode.
@SpringBootApplication
public class CommandlinerunnerApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(CommandlinerunnerApplication.class);
app.addInitializers((ApplicationContextInitializer<GenericApplicationContext>) context ->
context.registerBean(Foo.class));
app.run(args);
}
}
public class Foo {
public Foo() {
System.out.println("Foo constructor");
}
}
A look at the generated code shows that Foo__BeanDefinitions
generated during AOT transformations based on the initializer is created as expected, but it seems the second invocation comes from the fact that SpringApplication#applyInitializers
is still invoked at runtime.
Notice that on native, this second invocation fails with Runtime reflection is not supported for public com.example.commandlinerunner.Foo()
because unlike the AOT generated one, it requires ExecutableMode#INVOKE
reflection hints (not inferred because not needed by the AOT generated code which is fine with ExecutableMode#INTROSPECT
).
Both issues should be solved by removing the second invocation of the initializers, but this need to be explored because it could involve unwanted side effects with some initializers.