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