Skip to content

Commit

Permalink
kagkarlsson#491 - Eagerly load DBSchedulerStarter
Browse files Browse the repository at this point in the history
  • Loading branch information
NicklasWallgren committed May 20, 2024
1 parent 823c9d2 commit d751b37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d751b37

Please sign in to comment.