[英]Spring pool connections with MySQL
I have (hypothetically) the following servers for my application; (假设)我的应用程序具有以下服务器; I work with MySQL. 我使用MySQL。
1) Database used by the application (server located in Japan) 1)应用程序使用的数据库(位于日本的服务器)
2) Database Backup (server located in Peru) 2)数据库备份(服务器位于秘鲁)
3) Emergency Database (server located in the US) 3)紧急数据库(位于美国的服务器)
I have a couple of questions about the capabilities of Spring: 关于Spring的功能,我有几个问题:
A) How I can persist simultaneously in all datasources? A)如何在所有数据源中同时存在?
B) How I can create a connection pool in Spring so that if my first datasource does not respond, the system automatically works with the second datasource? B)如何在Spring中创建连接池,以便如果我的第一个数据源不响应,系统将自动使用第二个数据源?
This is my actual applicationContext-datasource.xml
这是我实际的applicationContext-datasource.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>META-INF/database.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}"/>
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
Regards 问候
If I had the same problem I would try solve it outside of the application boundaries, so as not to have the application coupled with database topology . 如果我遇到相同的问题,我会尝试在应用程序范围之外解决它,以免使应用程序与数据库拓扑耦合。
I should request to persist an object to a logical entity perceived by Spring/Hibernate as a database and which is not part of the application, but it's aware of the database topology and availability, then delegate to it the distribution of the data. 我应该请求将一个对象持久化为Spring / Hibernate认为是数据库的逻辑实体,它不是应用程序的一部分,但是它知道数据库的拓扑和可用性,然后将数据的分配委托给它。
Normally you can solve this through: 通常,您可以通过以下方法解决此问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.