From cd15cbdc79f2ce13b54fe75668e54db9df072d19 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 30 Sep 2020 10:10:16 +0200 Subject: [PATCH] Do not execute datasource initialization in a separate thread This commit makes sure that `data.sql` is performed in the same thread as the one initializing the JPA container. Closes gh-22852 --- .../orm/jpa/DataSourceInitializedPublisher.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java index 9896a82af3..541405b555 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java @@ -35,7 +35,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceSchemaCreatedEvent; import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; -import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.type.AnnotationMetadata; import org.springframework.orm.jpa.JpaDialect; import org.springframework.orm.jpa.JpaVendorAdapter; @@ -194,11 +193,7 @@ class DataSourceInitializedPublisher implements BeanPostProcessor { @Override public void postProcessEntityManagerFactory(EntityManagerFactory entityManagerFactory) { this.delegate.postProcessEntityManagerFactory(entityManagerFactory); - AsyncTaskExecutor bootstrapExecutor = this.factoryBean.getBootstrapExecutor(); - if (bootstrapExecutor != null) { - bootstrapExecutor.execute(() -> DataSourceInitializedPublisher.this - .publishEventIfRequired(this.factoryBean, entityManagerFactory)); - } + publishEventIfRequired(this.factoryBean, entityManagerFactory); } }