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

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

Closed
Davidonium opened this issue Dec 30, 2020 · 1 comment
Assignees
Milestone

Comments

@Davidonium
Copy link

@Davidonium Davidonium commented Dec 30, 2020

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?

@Davidonium Davidonium changed the title dataSource in JdbcSessionConfiguration$jdbcSessionDataSourceInitializer should be annotated with @SpringSessionDataSource dataSource in JdbcSessionConfiguration$jdbcSessionDataSourceInitializer should be annotated with @SpringSessionDataSource Dec 30, 2020
@wilkinsona
Copy link
Member

@wilkinsona wilkinsona commented Jan 4, 2021

Thanks for the suggestion. I think that makes sense and would align the DataSource that's injected into the JdbcSessionDataSourceInitializer with the DataSource that's injected into Boot's JdbcHttpSessionConfiguration subclass.

@wilkinsona wilkinsona added this to the 2.3.x milestone Jan 4, 2021
@wilkinsona wilkinsona self-assigned this Jan 12, 2021
@wilkinsona wilkinsona changed the title dataSource in JdbcSessionConfiguration$jdbcSessionDataSourceInitializer should be annotated with @SpringSessionDataSource Auto-configured JdbcSessionDataSourceInitializer does not use the @SpringSessionDataSource if available Jan 12, 2021
@wilkinsona wilkinsona modified the milestones: 2.3.x, 2.3.8 Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants