Skip to content

Commit

Permalink
fix: Eagerly load DBSchedulerStarter (491) (#492)
Browse files Browse the repository at this point in the history
## Brief, plain english overview of your changes here
Excludes DbSchedulerStarter from being lazily initialized.

## Fixes
The DbSchedulerStarter isn't created in a application where lazy
initialization is enabled via `spring.main.lazy-initialization=true`.

Fixes: #491

## Reminders
- [X] Added/ran automated tests
- [ ] Update README and/or examples
- [x] Ran `mvn spotless:apply`
  • Loading branch information
NicklasWallgren authored May 28, 2024
1 parent b0e981b commit 21f250f
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 @@ -39,6 +39,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 @@ -192,6 +193,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 21f250f

Please sign in to comment.