Change default BootstrapMode for JPA repositories
Change the default `BootstrapMode` for auto-configured `JpaRepositories` to `BootstrapMode.DEFERRED` to allow the initialization of `EntityManagerFactory` to be parallelized for increased startup efficiency. Prior to this change, the default BootstrapMode for all auto-configured Spring Data repositories was `BootstrapMode.DEFAULT`. Closes gh-16230
This commit is contained in:
committed by
Phillip Webb
parent
ae3bdc79f3
commit
288889685d
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,6 +56,7 @@ import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Josh Long
|
||||
* @author Scott Frederick
|
||||
* @since 1.0.0
|
||||
* @see EnableJpaRepositories
|
||||
*/
|
||||
@@ -95,7 +96,7 @@ public class JpaRepositoriesAutoConfiguration {
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "bootstrap-mode",
|
||||
havingValue = "deferred", matchIfMissing = false)
|
||||
havingValue = "deferred", matchIfMissing = true)
|
||||
static class DeferredBootstrapMode {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class JpaRepositoriesRegistrar extends AbstractRepositoryConfigurationSourceSupport {
|
||||
|
||||
@@ -56,7 +57,7 @@ class JpaRepositoriesRegistrar extends AbstractRepositoryConfigurationSourceSupp
|
||||
|
||||
@Override
|
||||
protected BootstrapMode getBootstrapMode() {
|
||||
return (this.bootstrapMode == null) ? super.getBootstrapMode() : this.bootstrapMode;
|
||||
return (this.bootstrapMode == null) ? BootstrapMode.DEFERRED : this.bootstrapMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,6 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Oliver Gierke
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class JpaRepositoriesAutoConfigurationTests {
|
||||
|
||||
@@ -85,7 +86,7 @@ class JpaRepositoriesAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenBootstrappingModeIsLazyWithMultipleAsyncExecutorBootstrapExecutorIsConfigured() {
|
||||
void whenBootstrapModeIsLazyWithMultipleAsyncExecutorBootstrapExecutorIsConfigured() {
|
||||
this.contextRunner.withUserConfiguration(MultipleAsyncTaskExecutorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class,
|
||||
TaskSchedulingAutoConfiguration.class))
|
||||
@@ -96,7 +97,7 @@ class JpaRepositoriesAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenBootstrappingModeIsLazyWithSingleAsyncExecutorBootstrapExecutorIsConfigured() {
|
||||
void whenBootstrapModeIsLazyWithSingleAsyncExecutorBootstrapExecutorIsConfigured() {
|
||||
this.contextRunner.withUserConfiguration(SingleAsyncTaskExecutorConfiguration.class)
|
||||
.withPropertyValues("spring.data.jpa.repositories.bootstrap-mode=lazy")
|
||||
.run((context) -> assertThat(
|
||||
@@ -105,7 +106,7 @@ class JpaRepositoriesAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenBootstrappingModeIsDeferredBootstrapExecutorIsConfigured() {
|
||||
void whenBootstrapModeIsDeferredBootstrapExecutorIsConfigured() {
|
||||
this.contextRunner.withUserConfiguration(MultipleAsyncTaskExecutorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class,
|
||||
TaskSchedulingAutoConfiguration.class))
|
||||
@@ -116,7 +117,7 @@ class JpaRepositoriesAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenBootstrappingModeIsDefaultBootstrapExecutorIsNotConfigured() {
|
||||
void whenBootstrapModeIsDefaultBootstrapExecutorIsNotConfigured() {
|
||||
this.contextRunner.withUserConfiguration(MultipleAsyncTaskExecutorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class,
|
||||
TaskSchedulingAutoConfiguration.class))
|
||||
@@ -124,6 +125,16 @@ class JpaRepositoriesAutoConfigurationTests {
|
||||
context.getBean(LocalContainerEntityManagerFactoryBean.class).getBootstrapExecutor()).isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bootstrapModeIsDeferredByDefault() {
|
||||
this.contextRunner.withUserConfiguration(MultipleAsyncTaskExecutorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class,
|
||||
TaskSchedulingAutoConfiguration.class))
|
||||
.run((context) -> assertThat(
|
||||
context.getBean(LocalContainerEntityManagerFactoryBean.class).getBootstrapExecutor())
|
||||
.isEqualTo(context.getBean("applicationTaskExecutor")));
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableScheduling
|
||||
@Import(TestConfiguration.class)
|
||||
|
||||
Reference in New Issue
Block a user