Due to ApplicationEventPublisher.publishEvent was running asynchronous. so the class DataSourceInitializerInvoker's method initialize and onApplicationEvent maybe run concurrent, It will cause DataSourceInitializer.initSchema() duplicate execution. the source code were following:lineNumber at 76 and 91
private void initialize(DataSourceInitializer initializer) {
try {
this.applicationContext.publishEvent(
new DataSourceSchemaCreatedEvent(initializer.getDataSource()));
// The listener might not be registered yet, so don't rely on it.
if (!this.initialized) {
this.dataSourceInitializer.initSchema();
this.initialized = true;
}
} catch (IllegalStateException ex) {
logger.warn("Could not send event to complete DataSource initialization ("
+ ex.getMessage() + ")");
}
}
@Override
public void onApplicationEvent(DataSourceSchemaCreatedEvent event) {
// NOTE the event can happen more than once and
// the event datasource is not used here
DataSourceInitializer initializer = getDataSourceInitializer();
if (!this.initialized && initializer != null) {
initializer.initSchema();
this.initialized = true;
}
}
Comment From: wilkinsona
initialize
is only called from afterPropertiesSet
which is called as part of bean initialization. I would not expect another method on the bean to be called until its initialization has completed.
Please provide a minimal sample that reproduces the problem so that we can see exactly what’s happening. That can either be a zip attached to this issue or a separate repository on GitHub.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.