我想创建基于注释的拦截器,它将记录主数据库无法为请求提供服务的当前数据库详细信息,并且辅助数据库将开始为应用程序提供支持。
我在下面提到的链接中找到了代码,但我找不到特定的orcl注释,它必须用于注释,如下面的@Aspect for aop,请帮助找到这个。
<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>
基本上,没有开箱即用的“Oracle”注释可用于使rac故障转移拦截器工作。但是添加新的自定义注释很容易,它将为您完成工作。
只要sprig数据oracle在你的classpath中
Mavel pom.hml
<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故障转移拦截器应该在您的跨国拦截器之前进行,即当事务已经处于活动状态时进行故障转移拦截时,故障转移将无法按预期工作。