diff --git a/spring-modulith-runtime/src/main/java/org/springframework/modulith/runtime/autoconfigure/SpringModulithRuntimeAutoConfiguration.java b/spring-modulith-runtime/src/main/java/org/springframework/modulith/runtime/autoconfigure/SpringModulithRuntimeAutoConfiguration.java index 8f1136ed..dda34a8b 100644 --- a/spring-modulith-runtime/src/main/java/org/springframework/modulith/runtime/autoconfigure/SpringModulithRuntimeAutoConfiguration.java +++ b/spring-modulith-runtime/src/main/java/org/springframework/modulith/runtime/autoconfigure/SpringModulithRuntimeAutoConfiguration.java @@ -42,8 +42,8 @@ import org.springframework.util.Assert; /** - * Auto-configuration to register a {@link SpringBootApplicationRuntime} and {@link ApplicationModulesRuntime} as Spring - * Bean. + * Auto-configuration to register a {@link SpringBootApplicationRuntime}, a {@link ApplicationModulesRuntime} and an + * {@link ApplicationListener} to invoke all {@link ApplicationModuleInitializer}s as Spring Bean. * * @author Oliver Drotbohm */ @@ -51,29 +51,31 @@ class SpringModulithRuntimeAutoConfiguration { private static final Logger LOGGER = LoggerFactory.getLogger(SpringModulithRuntimeAutoConfiguration.class); - private final AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); + private static final AsyncTaskExecutor EXECUTOR = new SimpleAsyncTaskExecutor(); @Bean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) @ConditionalOnMissingBean(ApplicationRuntime.class) - SpringBootApplicationRuntime modulithsApplicationRuntime(ApplicationContext context) { + static SpringBootApplicationRuntime modulithsApplicationRuntime(ApplicationContext context) { return new SpringBootApplicationRuntime(context); } @Bean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) @ConditionalOnMissingBean - ApplicationModulesRuntime modulesRuntime(ApplicationRuntime runtime) { + static ApplicationModulesRuntime modulesRuntime(ApplicationRuntime runtime) { var mainClass = runtime.getMainApplicationClass(); - var modules = executor + var modules = EXECUTOR .submit(() -> ApplicationModulesBootstrap.initializeApplicationModules(mainClass)); return new ApplicationModulesRuntime(toSupplier(modules), runtime); } @Bean - ApplicationListener applicationModuleInitializingListener(ListableBeanFactory beanFactory) { + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) + static ApplicationListener applicationModuleInitializingListener( + ListableBeanFactory beanFactory) { return event -> {