Comment From: joshlong
demo. generate a new project with no changes to the build on the initializr. im using maven. also, add GraalVM.
add a sub-packge, app, under the root Boot package, com.example.demo:
package com.example.demo.app;
import org.springframework.beans.factory.BeanRegistrar;
import org.springframework.beans.factory.BeanRegistry;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
@Configuration
@Import(MyBeanRegistrar.class)
class MyConfig {}
class MyBeanRegistrar implements BeanRegistrar {
@Override
public void register(BeanRegistry registry, Environment env) {
registry.registerBean(MyRunner.class);
}
}
class MyRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
IO.println("Hello World");
}
}
u will get
Total time: 1.528 s
[INFO] Finished at: 2025-12-03T09:35:03-08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:4.0.0:process-aot (process-aot) on project demo: Unable to compile generated source
[ERROR] com.example.demo.app.MyBeanRegistrar is not public in com.example.demo.app; cannot be accessed from outside package /Users/jlong/Downloads/demo/target/spring-aot/main/sources/com/example/demo/DemoApplication__ApplicationContextInitializer.java 3:28
[ERROR] com.example.demo.app.MyBeanRegistrar is not public in com.example.demo.app; cannot be accessed from outside package /Users/jlong/Downloads/demo/target/spring-aot/main/sources/com/example/demo/DemoApplication__ApplicationContextInitializer.java 40:5
[ERROR] com.example.demo.app.MyBeanRegistrar is not public in com.example.demo.app; cannot be accessed from outside package /Users/jlong/Downloads/demo/target/spring-aot/main/sources/com/example/demo/DemoApplication__ApplicationContextInitializer.java 40:43
[ERROR] com.example.demo.app.MyBeanRegistrar is not public in com.example.demo.app; cannot be accessed from outside package /Users/jlong/Downloads/demo/target/spring-aot/main/sources/com/example/demo/DemoApplication__ApplicationContextInitializer.java 41:117
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
➜ demo