当前位置:网站首页>How to realize the usage of connecting multiple databases in idel
How to realize the usage of connecting multiple databases in idel
2022-07-01 09:12:00 【CSDN Q & A】
The only data connected to my project is the local database , How to connect two databases , The primary database is a local database , The secondary database is 192.168.1.123 The database above , When I log in, I access my master database , When I query, the data may be obtained from my secondary database

Take the answer :
Set master-slave Library

** establish DataSourceConfig **
@Configurationpublic class DataSourceConfig { @Bean(name = "dbOneDataSource") @Primary // application.yml In the corresponding db Corresponding to the company's own air grid system database @ConfigurationProperties(prefix = "spring.db1") public DataSource dbOneDataSource() { return DataSourceBuilder.create().build(); } @Bean(name = "dbTwoDataSource") // application.yml Corresponding database in 1 @ConfigurationProperties(prefix = "spring.db2") public DataSource dbTwoDataSource() { return DataSourceBuilder.create().build(); } //@Bean(name = "dbThreeDataSource") // application.yml In the corresponding database 2 //@ConfigurationProperties(prefix = "spring.db3") /*public DataSource dbThreeDataSource() { return DataSourceBuilder.create().build(); }*/}To write MybatisConfig
```java /** * The first database SqlSessionFactory && SqlSessionTemplate establish */ @Configuration // Corresponding to the binding data source mapper[ First use ] @MapperScan(basePackages = {
"com.hqkj.httpdemo.demo.one.mapper"}, sqlSessionFactoryRef = "sqlSessionFactoryOne", sqlSessionTemplateRef = "sqlSessionTemplateOne") public static class DBOne{ @Resource DataSource dbOneDataSource; @Bean @Primary public SqlSessionFactory sqlSessionFactoryOne() throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dbOneDataSource); return factoryBean.getObject(); } @Bean @Primary public SqlSessionTemplate sqlSessionTemplateOne() throws Exception { SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactoryOne()); return template; } }```java/** * The second database SqlSessionFactory && SqlSessionTemplate establish */ @Configuration // Corresponding to the original data binding maper[ Second use ] @MapperScan(basePackages = {
"com.hqkj.httpdemo.demo.two.mapper"}, sqlSessionFactoryRef = "sqlSessionFactoryTwo", sqlSessionTemplateRef ="sqlSessionTemplateTwo" ) public static class DBTwo{ @Resource DataSource dbTwoDataSource; @Bean public SqlSessionFactory sqlSessionFactoryTwo() throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dbTwoDataSource); return factoryBean.getObject(); } @Bean public SqlSessionTemplate sqlSessionTemplateTwo() throws Exception { SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactoryTwo()); return template; } }边栏推荐
- [MFC development (17)] advanced list control list control
- Serialization, listening, custom annotation
- 2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
- 2.4 激活函数
- Jetson Nano 安装TensorFlow GPU及问题解决
- 如何解决固定资产管理和盘点的难题?
- 樹結構---二叉樹2非遞歸遍曆
- 3D打印Arduino 四轴飞行器
- FreeRTOS learning easy notes
- [pytorch] softmax function
猜你喜欢
![[interview brush 101] linked list](/img/52/d159bc66c0dbc44c1282a96cf6b2fd.png)
[interview brush 101] linked list

Vsync+ triple cache mechanism +choreographer

2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder

3D printing Arduino four axis aircraft

How to launch circle of friends marketing and wechat group activities
![2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder](/img/19/cce8d8a7cdcb1021166c46adf803c1.png)
2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder

Installing Oracle EE

I use flask to write the website "one"

Pain points and solutions of fixed assets management of group companies

【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
随机推荐
Shell script - array definition and getting array elements
2.4 activation function
如何高效拉齐团队认知
Redis -- lattice connects to redis cluster
Common interview questions for embedded engineers 2-mcu_ STM32
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的WS2812灯控系统
Microcomputer principle - bus and its formation
[ESP nanny level tutorial] crazy completion chapter - Case: gy906 infrared temperature measurement access card swiping system based on the Internet of things
Shell script - positional parameters (command line parameters)
[ESP nanny level tutorial] crazy completion chapter - Case: temperature and humidity monitoring system based on Alibaba cloud, applet and Arduino
[MFC development (17)] advanced list control list control
In the middle of the year, where should fixed asset management go?
Set the type of the input tag to number, and remove the up and down arrows
nacos簡易實現負載均衡
Installing Oracle EE
JCL and slf4j
Redis——Lettuce连接redis集群
Understanding and implementation of AVL tree
Principles of Microcomputer - Introduction
Jeecg restart alarm 40001