Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Eagerly load DBSchedulerStarter (491) #492

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading