Spring Dynamic Multi-data source

Source: Internet
Author: User

Spring SPRINGMVC MyBatis

Key points when configuring multiple data sources:

1. Note the configuration of the transaction interceptor

Transaction management in spring is bound to the data source, and once the program executes to the service layer (transaction management), because the transaction has been connected to the data source through the interceptor before entering the layer, it is not possible to switch the data source at that level.

Therefore, the tangent point (DataSource) should be configured on the upper level of the transaction, which is the controller layer.

Because the controller, service, DAO layer three is used

In the DAO layer, sqlsession is called to connect to the database and cannot be changed, because it is called sqlsession first, then through the function's pointcut.

At the service level, transactions are used. If you are at the service layer, you can only change the data source for the operation after the first operation.

So switch the data source, only in the controller layer, to do the pointcut. This allows the modified data source to be used when the transaction is invoked.

2. Oracle authorized read-only user

Create a new read-only user Myread

Give the read-only user the following roles: Connect, resource

Add read-only user-to-table SELECT permission, and authorize.

To add the name of the table owner before the table, use the following format when the user calls the data in the table

SELECT * from OWNER. USERS

Spring Dynamic Multi-data source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.