Skip to content

Commit

Permalink
GH-252 - Avoid premature initialization of SpringModulithRuntimeAutoC…
Browse files Browse the repository at this point in the history
…onfiguration.

Bean declarations are now entirely static.
  • Loading branch information
odrotbohm committed Aug 1, 2023
1 parent 04187a1 commit d665161
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,40 @@
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
*/
@AutoConfiguration
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<ApplicationStartedEvent> applicationModuleInitializingListener(ListableBeanFactory beanFactory) {
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
static ApplicationListener<ApplicationStartedEvent> applicationModuleInitializingListener(
ListableBeanFactory beanFactory) {

return event -> {

Expand Down

0 comments on commit d665161

Please sign in to comment.