java - Spring: separate datasource for read-only transactions -


Thanks for reading it.

I have 2 MySQL databases - write, I am thinking that the right situation is that my app uses the connection to the master for the read = wrong transaction Dada for readOnly = true transaction.

To implement this, I need to provide a valid connection based on the type of transaction existing. My data service level should not be known about which type of connection it uses and just using the injection SqlMapClient (I use iBatis) directly. This means that (if I get it right) injection SqlMapClient s should be proxied and the rep should be selected at runtime.

  Public class MyDataService {Private SqlMapClient sqlMap; @ Owned public mediate service (SQLMail client SQLMap) {this.sqlMap = sqlMap; } @ Transactional (readonly = true) public mediate should be Somadata () {// one example of square map should be linked to slave) @ TransxNyile (read only = false) Public Zero save MyData (MyData myData) {// Example of SQL map, Master should be used}}  

So the question is - How can I do this?

Thank you very much

This is an interesting idea, but you have a The hard work on hand is to make the code as a sign for the transfer manager, and in fact there is no meaningful advice anywhere, you will have to re-type or expand many spring infrastructure classes. Will happen.

So, unless you want to do this work, you can choose your best option for two specific SqlMapClient items in your DAO, and the appropriate one. @ Transaction related annotation must also indicate which transaction manager to use (assuming that you are using JpaTransactionManager instead of DataSourceTransactionManager ) , SqlMapClient . Match transaction manager in DataSource used by


Comments