代码之家  ›  专栏  ›  技术社区  ›  sunleo

春季启动处理中的Oracle数据库故障转移

  •  3
  • sunleo  · 技术社区  · 6 年前

    我想创建一个基于注释的拦截器,它将记录当前数据库的详细信息,无论主数据库在什么地方无法为请求提供服务器,辅助数据库都将开始为应用程序提供支持。

    我在上面提到的链接中找到了下面的代码,但是我找不到特定的orcl注释,这些注释必须用于下面的注释,比如aop的@aspect,请帮助找到这个。

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:orcl="http://www.springframework.org/schema/data/orcl"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/data/orcl
           http://www.springframework.org/schema/data/orcl/spring-data-orcl-1.0.xsd">
    
        <aop:config>
            <aop:advisor pointcut="execution(* *..PetStoreFacade.insertOrder(..))" 1 
                advice-ref="racFailoverInterceptor" order="1"/>
            <aop:advisor pointcut="execution(* *..PetStoreFacade.*(..))" 2 
                advice-ref="txAdvice"/>
        </aop:config>
    
        <orcl:rac-failover-interceptor id="racFailoverInterceptor"/> 3
    
        <tx:advice id="txAdvice">
            <tx:attributes>
                <tx:method name="insert*"/>
                <tx:method name="update*"/>
                <tx:method name="*" read-only="true"/>
            </tx:attributes>
        </tx:advice>
    
    </beans>
    

    https://docs.spring.io/spring-data/jdbc/old-docs/2.0.0.BUILD-SNAPSHOT/reference/html/orcl.failover.html

    1 回复  |  直到 6 年前
        1
  •  2
  •   Babl    6 年前

    基本上,没有现成的“Oracle”注释可用于使RAC故障转移拦截器工作。但是很容易添加新的自定义注释,这将为您完成工作。

    如果sprig数据oracle在您的类路径上

    maven pom.xml文件

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-oracle</artifactId>
        <version>1.2.1.RELEASE</version>
    </dependency>
    

    只需创建一个要使用的标记注释。

    package org.example;
    public @interface OracleFailover {
    // just a marker annotation, no body
    }
    

    为其配置顾问

    <aop:config>
        <aop:advisor 
           pointcut="@annotation(org.example.OracleFailover)" 
            advice-ref="racFailoverInterceptor" order="1"/>
    </aop:config>
    
    <orcl:rac-failover-interceptor id="racFailoverInterceptor"/>
    

    然后把它用在你的商业方法上

    package org.example;
    
    @Service
    public class SomeBusinessService {
        @OracleFailover
        void doSomethingWithOracle(){
            // body goes here
        }
    }
    

    记住,RAC故障转移拦截器应该先于您的跨国拦截器,也就是说,如果在事务已处于活动状态时完成故障转移拦截器,故障转移将无法按预期工作。