Spring MVC + mybaties Configuring multiple data sources

Source: Internet
Author: User

1: First configure the data source, can now be introduced in the configuration file, where I write directly in the spring configuration file

First, a single data source configuration file is given

The main changes are these two places,

Now look at the configuration of multiple data sources

Configure two data sources, note that the Bean ID is unique

Next is the problem of choosing the data source, the following bean directly load the spring configuration file, the ID is unique, the value of class is Dynamicdatasource this class in your project path

Once configured, the configuration information for the mybaties is then modified, but the data source configuration is

Now change it to the following

That is to change the value of the data source introduced in the id= "Sqlsessionfactory", the value of ref is changed to the value of the ID of the dynamically allocated data source Bean, and after the configuration file has been changed, we now write two classes.

The next step in the controller is to call the

It's ready,

Spring MVC + mybaties Configuring multiple data sources

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.