Skip to content

Provides a way for configuring after the datasource is initialized #28795

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

Closed
refeccd opened this issue Nov 24, 2021 · 8 comments
Closed

Provides a way for configuring after the datasource is initialized #28795

refeccd opened this issue Nov 24, 2021 · 8 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@refeccd
Copy link
Contributor

refeccd commented Nov 24, 2021

In the current version, the datasource can only be initialized through configuration, and the properties cannot be modified after initialization.
Although it is possible to modify datasource properties through BeanPostProcessor, do you want to add a more convenient method, such as Customizer callback?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 24, 2021
@wilkinsona
Copy link
Member

Thanks for the suggestion. Unfortunately, I don't understand the benefit that a customizer callback would bring. Can you please provide an example of what you would like to be able to do and explain why it isn't possible at the moment?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Nov 24, 2021
@refeccd
Copy link
Contributor Author

refeccd commented Nov 24, 2021

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 24, 2021
@refeccd
Copy link
Contributor Author

refeccd commented Nov 24, 2021

example updated

@wilkinsona
Copy link
Member

wilkinsona commented Nov 24, 2021

Thanks for the example.

You can already configure the DataSource in this way using configuration properties. For example, spring.datasource.hikari.datasourceproperties.example=alpha will result in the dataSourceProperties of the auto-configured HikariDataSource containing the key example and the value alpha. Assuming that the @Bean method for a DruidDataSource is annotated with @ConfigurationProperties("spring.datasource.druid"), you could do something similar with spring.datasource.druid.connectproperties.example=alpha.

Have you considered using this approach rather than a bean post-processor or you suggested customizer callback? As things stand, I can't see much, if any, benefit of the customizer callback over what's already supported.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Nov 24, 2021
@refeccd
Copy link
Contributor Author

refeccd commented Nov 24, 2021

If I want to provide a unified approach instead of do it in every service ,how to do it?
If the configuration is configured in the configuration file, then the user needs to be familiar with the configuration method of each datasource. If you switch to another data source, you need to reconfigure it, and there may be errors, such as spelling errors and inconsistent attributes. If you provide a callback, you can standardize the behavior in a unified third-party starter, shielding the underlying details

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 24, 2021
@wilkinsona
Copy link
Member

If I want to provide a unified approach instead of do it in every service ,how to do it?

A starter can either use a bean post-processor as I suggested above or it can provide the properties for different types of DataSource via an EnvironmentPostProcessor that adds a PropertySource. We'd like to improve the mechanism (#24688) for contributing application properties from a starter, but this is how I'd implement this at the moment.

I'll flag this for team attention to see if the rest of the team feel that a customizer callback is warranted here.

@wilkinsona wilkinsona added for: team-attention An issue we'd like other members of the team to review and removed status: feedback-provided Feedback has been provided labels Nov 29, 2021
@philwebb
Copy link
Member

I think there's a danger that we could over do the Customizer callbacks if we're not careful. It feels like this use-case isn't all that common so I think the BeanPostProcessor is probably the best approach.

@refeccd
Copy link
Contributor Author

refeccd commented Nov 30, 2021

Well, I 've implemented it with a BeanPostProcessor

@refeccd refeccd closed this as completed Nov 30, 2021
@philwebb philwebb added status: declined A suggestion or change that we don't feel we should currently apply and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants