Stop deferring JPA bootstrap mode by default
This commit changes the default value of bootstrap-mode to "default" rather than "deferred" so that the JPA infrastructure starts in the main thread rather than asynchronously. Closes gh-24249
This commit is contained in:
parent
f84cb1b765
commit
06671aa50e
@ -96,13 +96,12 @@ public class JpaRepositoriesAutoConfiguration {
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "bootstrap-mode",
|
||||
havingValue = "deferred", matchIfMissing = true)
|
||||
havingValue = "deferred")
|
||||
static class DeferredBootstrapMode {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "bootstrap-mode", havingValue = "lazy",
|
||||
matchIfMissing = false)
|
||||
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "bootstrap-mode", havingValue = "lazy")
|
||||
static class LazyBootstrapMode {
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class JpaRepositoriesRegistrar extends AbstractRepositoryConfigurationSourceSupp
|
||||
|
||||
@Override
|
||||
protected BootstrapMode getBootstrapMode() {
|
||||
return (this.bootstrapMode == null) ? BootstrapMode.DEFERRED : this.bootstrapMode;
|
||||
return (this.bootstrapMode == null) ? BootstrapMode.DEFAULT : this.bootstrapMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -622,7 +622,7 @@
|
||||
"name": "spring.data.jpa.repositories.bootstrap-mode",
|
||||
"type": "org.springframework.data.repository.config.BootstrapMode",
|
||||
"description": "Bootstrap mode for JPA repositories.",
|
||||
"defaultValue": "deferred"
|
||||
"defaultValue": "default"
|
||||
},
|
||||
{
|
||||
"name": "spring.data.jpa.repositories.enabled",
|
||||
|
@ -126,13 +126,12 @@ class JpaRepositoriesAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bootstrapModeIsDeferredByDefault() {
|
||||
void bootstrapModeIsDefaultByDefault() {
|
||||
this.contextRunner.withUserConfiguration(MultipleAsyncTaskExecutorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class,
|
||||
TaskSchedulingAutoConfiguration.class))
|
||||
.run((context) -> assertThat(
|
||||
context.getBean(LocalContainerEntityManagerFactoryBean.class).getBootstrapExecutor())
|
||||
.isEqualTo(context.getBean("applicationTaskExecutor")));
|
||||
context.getBean(LocalContainerEntityManagerFactoryBean.class).getBootstrapExecutor()).isNull());
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
@ -3839,6 +3839,8 @@ To enable deferred or lazy bootstrapping, set the configprop:spring.data.jpa.rep
|
||||
When using deferred or lazy bootstrapping, the auto-configured `EntityManagerFactoryBuilder` will use the context's `AsyncTaskExecutor`, if any, as the bootstrap executor.
|
||||
If more than one exists, the one named `applicationTaskExecutor` will be used.
|
||||
|
||||
NOTE: When using deferred or lazy bootstraping, make sure to defer any access to the JPA infrastructure after the application context bootstrap phase.
|
||||
|
||||
TIP: We have barely scratched the surface of Spring Data JPA.
|
||||
For complete details, see the {spring-data-jdbc-docs}[Spring Data JPA reference documentation].
|
||||
|
||||
|
@ -103,11 +103,11 @@ public @interface DataJpaTest {
|
||||
|
||||
/**
|
||||
* The {@link BootstrapMode} for the test repository support. Defaults to
|
||||
* {@link BootstrapMode#LAZY}.
|
||||
* {@link BootstrapMode#DEFAULT}.
|
||||
* @return the {@link BootstrapMode} to use for testing the repository
|
||||
*/
|
||||
@PropertyMapping("spring.data.jpa.repositories.bootstrap-mode")
|
||||
BootstrapMode bootstrapMode() default BootstrapMode.LAZY;
|
||||
BootstrapMode bootstrapMode() default BootstrapMode.DEFAULT;
|
||||
|
||||
/**
|
||||
* Determines if default filtering should be used with
|
||||
|
@ -109,9 +109,9 @@ class DataJpaTestIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bootstrapModeIsLazyByDefault() {
|
||||
void bootstrapModeIsDefaultByDefault() {
|
||||
assertThat(this.applicationContext.getEnvironment().getProperty("spring.data.jpa.repositories.bootstrap-mode"))
|
||||
.isEqualTo(BootstrapMode.LAZY.name());
|
||||
.isEqualTo(BootstrapMode.DEFAULT.name());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user