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
This commit is contained in:
Stephane Nicoll 2020-09-30 10:10:16 +02:00
parent 789fafadac
commit cd15cbdc79
1 changed files with 1 additions and 6 deletions

View File

@ -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);
}
}