Spring+mybatis configuration of multiple data sources

Source: Internet
Author: User

Way One:

See blog https://www.cnblogs.com/AmbitiousMice/p/6027674.html

This way, you need to set the corresponding data source each time you call DAO.

Way two:

Configure the relevant DAO interface for the corresponding data source directly in the MyBatis configuration file (mapper.xml configuration file)

1. Database configuration file

Jdbc.driver=com.mysql.jdbc.driverjdbc.url=jdbc:mysql://duingold.mysql.rds.aliyuncs.com/pbossvisual? Characterencoding=utf-8jdbc.user=driverjdbc.password=driver123456pbossdb.jdbc.driver= com.mysql.jdbc.driverpbossdb.jdbc.url=jdbc:mysql://duingold.mysql.rds.aliyuncs.com/pbossdb?characterencoding= utf-8pbossdb.jdbc.user=driverpbossdb.jdbc.password=driver123456

Different data source configuration, note that different data sources corresponding to the Mapper.xml file is not the same. See the red box to ensure that the data source of the corresponding database is accessed when the interface is called.

2. Configuration of data source 1.

3. Configuration of Data source 2

 

4. Import the configuration files for two different data sources in the spring configuration file.

Spring+mybatis configuration of 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.