Skip to content

support read only connection datasource #8189

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
xenoterracide opened this issue Feb 3, 2017 · 5 comments
Closed

support read only connection datasource #8189

xenoterracide opened this issue Feb 3, 2017 · 5 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@xenoterracide
Copy link
Contributor

xenoterracide commented Feb 3, 2017

read only slaves are a fairly common thing. It would be nice if spring boot could support this configuration out of the box for transactions marked as read only with perhaps a secondary "array" of read only datasource configurations (if you have more than one slave).

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

Thanks for the suggestion. Unfortunately, I don't think we really want to get into the business of auto-configuring multiple data sources. Figuring out the user's intent would start to get very complicated when something like Hibernate is thrown into the mix as well. We have an open issue to provide an example of how to configure multiple data sources. It actually links to a couple of existing examples that may be of interest.

Routing read-only requests to a slave is only one example of dynamic routing and there are a huge number of other possibilities. Given this, I don't think it makes sense for Boot to provide one specific custom routing logic implementation. I think that Spring Framework's already got this right. It provides AbstractRoutingDataSource as helpful base class for your custom logic and then leaves you just to write the logic that suits your specific needs.

To summarise, the recommendation is:

  • Configure multiple data sources manually to meet your needs
  • Use AbstractRoutingDataSource as the foundation for your custom routing logic

@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 3, 2017
@andyfeller
Copy link

@wilkinsona How would you recommend configuring a single data source as readOnly?

I'm autowiring beans via @ConfigurationProperties annotation to instantiate an arbitrary number of DataSourceProperties instances where I occasionally need to mark 1+ of them as readOnly. I'm not using @transactional annotation as I need this across the board for a given data source.

Thanks!

@wilkinsona
Copy link
Member

@andyfeller This isn't a great place for questions. We prefer that people use Gitter or Stack Overflow. That said, it depends on your database, doesn't it? I'd probably configure a Datasource with credentials for a user that only has read permissions.

@martin-g
Copy link

martin-g commented Feb 8, 2017

@wilkinsona Is Gitter a good place ? I am not able to find a way to search in its archives. If it is not possible to use its history then the provided solutions there are not very useful. People will ask the same questions again and again.

@wilkinsona
Copy link
Member

You can search on Gitter. There's a magnifying glass icon on the left-hand side of its UI.

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

5 participants