Commit cd15cbdc authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent 789fafad
...@@ -35,7 +35,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceSchemaCreatedEvent; ...@@ -35,7 +35,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceSchemaCreatedEvent;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.orm.jpa.JpaDialect; import org.springframework.orm.jpa.JpaDialect;
import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.JpaVendorAdapter;
...@@ -194,11 +193,7 @@ class DataSourceInitializedPublisher implements BeanPostProcessor { ...@@ -194,11 +193,7 @@ class DataSourceInitializedPublisher implements BeanPostProcessor {
@Override @Override
public void postProcessEntityManagerFactory(EntityManagerFactory entityManagerFactory) { public void postProcessEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
this.delegate.postProcessEntityManagerFactory(entityManagerFactory); this.delegate.postProcessEntityManagerFactory(entityManagerFactory);
AsyncTaskExecutor bootstrapExecutor = this.factoryBean.getBootstrapExecutor(); publishEventIfRequired(this.factoryBean, entityManagerFactory);
if (bootstrapExecutor != null) {
bootstrapExecutor.execute(() -> DataSourceInitializedPublisher.this
.publishEventIfRequired(this.factoryBean, entityManagerFactory));
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment