Skip to content

Auto-configured JdbcSessionDataSourceInitializer does not use the @SpringSessionDataSource if available #24624

@Davidonium

Description

@Davidonium

So today I was happy coding a Spring boot project of mine and wanted to use a file based session using H2 for a development environment. Since my application used another type of primary datasource (postgresql) I went on to figure out how to do it.

After setting my own beans, the application failed because the initializer was not run on the proper DataSource, it used the primary one. After some code digging I found out that the bean in spring boot is configured like this:

	@Bean
	@ConditionalOnMissingBean
	JdbcSessionDataSourceInitializer jdbcSessionDataSourceInitializer(DataSource dataSource,
			ResourceLoader resourceLoader, JdbcSessionProperties properties) {
		return new JdbcSessionDataSourceInitializer(dataSource, resourceLoader, properties);
	}

After finding this out, I happily defined my own JdbcSessionDataSourceInitializer bean annotating dataSource with @SpringSessionDataSource and went on coding. After some thinking I believe this makes sense to be changed in the library.

The end result would be

	@Bean
	@ConditionalOnMissingBean
	JdbcSessionDataSourceInitializer jdbcSessionDataSourceInitializer(@SpringSessionDataSource DataSource dataSource,
			ResourceLoader resourceLoader, JdbcSessionProperties properties) {
		return new JdbcSessionDataSourceInitializer(dataSource, resourceLoader, properties);
	}

Thoughts?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions