Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatabasePopulatorConfigUtils should only set a populator if matching scripts are defined #23405

Closed
MateuszStefek opened this issue Aug 2, 2019 · 0 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@MateuszStefek
Copy link

In my project, we define database initialization scripts via jdbc:initialize-database element.

        <jdbc:initialize-database data-source="dataSource">
            <jdbc:script location="classpath:db/schema.mysql.sql"/>
            <jdbc:script location="classpath:db/data.sql"/>
        </jdbc:initialize-database>

There are no cleanup scripts (no entries with execution="DESTROY"), yet the DataSourceInitializer bean tries to open a database connection when the context is shutting down. This slows down the shutdown process, especially when the connection times out.

The source code of DataSourceInitializer contains a null check on this.databaseCleaner:

	@Override
	public void destroy() {
		execute(this.databaseCleaner);
	}

	private void execute(DatabasePopulator populator) {
		Assert.state(this.dataSource != null, "DataSource must be set");
		if (this.enabled && populator != null) {
			DatabasePopulatorUtils.execute(populator, this.dataSource);
		}
	}

However, DatabasePopulatorConfigUtils.setDatabasePopulator always creates a non-null value for databaseCleaner, even if the object is effectively a no-op.

The problem happens in spring-jdbc 4.3.14 and 5.1.7

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 2, 2019
@MateuszStefek MateuszStefek changed the title InitializeDatabaseBeanDefinitionParser creates non-null value DatasourceInitialier.databaseCleaner even if there are no cleanup scripts InitializeDatabaseBeanDefinitionParser sets a non-null DatasourceInitialier.databaseCleaner even if there are no cleanup scripts Aug 2, 2019
@rstoyanchev rstoyanchev added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Nov 10, 2021
@snicoll snicoll changed the title InitializeDatabaseBeanDefinitionParser sets a non-null DatasourceInitialier.databaseCleaner even if there are no cleanup scripts DatabasePopulatorConfigUtils should only set a populator if matching scripts are defined Sep 25, 2023
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 25, 2023
@snicoll snicoll added this to the 6.x Backlog milestone Sep 25, 2023
@jhoeller jhoeller added type: enhancement A general enhancement and removed type: bug A general bug labels Dec 23, 2023
@jhoeller jhoeller self-assigned this Dec 23, 2023
@jhoeller jhoeller modified the milestones: 6.x Backlog, 6.1.3 Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants