I believe that if you have configured too many data sources or are about to configure multiple data sources, you will find that there are probably the following schemes on the Internet:
- 1. Use AOP slice for dynamic data source switching
- 2. Use
basePackagesConfigure different mapper directories and templates
- 3. Database agent middleware
Both methods can realize multiple data sources, but each has its own disadvantages:
- 1. Multiple data sources cannot be realized
XAThings (Global things Management)|
JTA）This disadvantage is very fatal. It is useless to have multiple data sources but no global things. There are many posts and tutorials on the Internet. Although the configuration is slightly simple, it is useless if you want to use global things.
- 2. This method can be combined
JTARealize the overall situation. At present, I also run online in this way in my business. After many debugging and online operation and maintenance, there is no doubt that there is a problem is trouble! You will encounter the need for integration
druidConnection pool and global things. If you find online posts and follow the process, there may still be some small problems after matching.
- 3. Data source proxy may be a good way. Most giant companies adopt this method, and developers do not have to consider these problems. They can use proxy for cutting and connection pool. However, there is a very embarrassing problem that open source is not easy to use, because many businesses are not suitable for their own business, And their own development is unrealistic and the cost is too high.
At this time, I’m thinking about why we can’t directly introduce a dependency like other language frameworks
ymlJust configure it in the file, and all have the simplest scheme now.
I hope you can support star and add other dependent simple integration in the future.
<dependency> <groupId>com.louislivi.fastdep</groupId> <artifactId>fastdep-datasource</artifactId> <version>1.0.0</version> </dependency>
compile group: 'com.louislivi.fastdep', name: 'fastdep-datasource', version: '1.0.0'
Is this over?
Yes, it’s that simple.
Is it very simple? If you go to the online poster, you will find that it is similar. It teaches you to add files for configuration all the time. If it is
MapperScanAdd a data source, and add another one every time
BeanIn fact, it is very simple. If you are interested, you can see the source code.
Prevent other questions from posting me completely
pom.xmlDependencies introduced under:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.1.5.RELEASE</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency> <dependency> <groupId>com.louislivi.fastdep</groupId> <artifactId>fastdep-datasource</artifactId> <version>1.0.0</version> </dependency> </dependencies>
I hope you can support open source and give me a little star. In the future, we will continue to develop other dependent integration and current multi data optimization support
HibernateAnd even compatible with other frameworks.
javaIntegration dependency is simpler. We also recruit like-minded people here
coderWork together to improve the project.
This work adoptsCC agreement, reprint must indicate the author and the link to this article