From d751b378ae20b76e673aa2fa311888e5c14a314d Mon Sep 17 00:00:00 2001 From: Nicklas Wallgren Date: Mon, 20 May 2024 07:53:50 +0200 Subject: [PATCH] #491 - Eagerly load DBSchedulerStarter --- .../autoconfigure/DbSchedulerAutoConfiguration.java | 6 ++++++ .../DbSchedulerAutoConfigurationTest.java | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/db-scheduler-boot-starter/src/main/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfiguration.java b/db-scheduler-boot-starter/src/main/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfiguration.java index 3162dc7a..9dc6f138 100644 --- a/db-scheduler-boot-starter/src/main/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfiguration.java +++ b/db-scheduler-boot-starter/src/main/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfiguration.java @@ -40,6 +40,7 @@ import javax.sql.DataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.LazyInitializationExcludeFilter; import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -196,6 +197,11 @@ public DbSchedulerStarter dbSchedulerStarter(Scheduler scheduler) { return new ImmediateStart(scheduler); } + @Bean + public LazyInitializationExcludeFilter eagerDbSchedulerStarter() { + return LazyInitializationExcludeFilter.forBeanTypes(DbSchedulerStarter.class); + } + private static DataSource configureDataSource(DataSource existingDataSource) { if (existingDataSource instanceof TransactionAwareDataSourceProxy) { log.debug("Using an already transaction aware DataSource"); diff --git a/db-scheduler-boot-starter/src/test/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfigurationTest.java b/db-scheduler-boot-starter/src/test/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfigurationTest.java index 6487db4a..985585c4 100644 --- a/db-scheduler-boot-starter/src/test/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfigurationTest.java +++ b/db-scheduler-boot-starter/src/test/java/com/github/kagkarlsson/scheduler/boot/autoconfigure/DbSchedulerAutoConfigurationTest.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.LazyInitializationExcludeFilter; import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; @@ -241,6 +242,17 @@ public void it_should_use_custom_stats_registry_if_present_in_context() { }); } + @Test + void it_should_exclude_db_scheduler_starter_from_lazy_init() { + ctxRunner.run( + (context) -> { + LazyInitializationExcludeFilter filter = + context.getBean(LazyInitializationExcludeFilter.class); + + assertThat(filter.isExcluded(null, null, DbSchedulerStarter.class)).isTrue(); + }); + } + @Configuration static class SingleTaskConfiguration { @Bean