0

私のアプリケーションには (仮説として) 次のサーバーがあります。私はMySQLを使用しています。

1) アプリケーションが使用するデータベース (日本にあるサーバー)
2) データベースのバックアップ (ペルーにあるサーバー)
3) 緊急データベース (米国にあるサーバー)

Spring の機能についていくつか質問があります。

A) すべてのデータソースで同時に保持するにはどうすればよいですか?

B) Spring で接続プールを作成して、最初のデータソースが応答しない場合にシステムが自動的に 2 番目のデータソースで動作するようにするにはどうすればよいですか?

これが私の実際の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>

よろしく

4

1 に答える 1

0

同じ問題が発生した場合は、アプリケーションがデータベース トポロジと結合しないように、アプリケーションの境界の外で解決しようとします。

Spring/Hibernate によってデータベースとして認識され、アプリケーションの一部ではないが、データベースのトポロジと可用性を認識している論理エンティティにオブジェクトを永続化するように要求し、データの配布を委任する必要があります。

通常、これは次の方法で解決できます。

于 2013-03-16T09:54:35.970 に答える