我使用spring 3.0.5和hibernate。
如何避免在db commit之后调用拦截器?
appCtx.xml
<tx:annotation-driven order="10" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<aop:aspectj-autoproxy />
<bean id="domainProducerHandler" depends-on="domainEventService"
class="org.test.service.DomainProducerHandler" factory-method="aspectOf">
<property name="domainEventService" ref="domainEventService" />
<property name="order" value="1" />
</bean>
===================service class=====================
@SendDomainEvent
@Transactional
public ProtoMessage sendDonation(String aa) {
Domain domainObj = new Domain();
domainRepository.saveAndFlush(domainObj);
return domain;
}
==================interceptor class===================**
@AfterReturning(
pointcut="@annotation(org.test.service.SendDomainEvent)",
returning="retVal")
public void processDomainReturn(Object retVal) {
....
try {
domainEventService.publishToQueue(endDonationSuccessEvent);
} catch (Exception e) {
log.error("error during send endDonationSuccessEvent: " + e);
}
}
Interceptor类实现Ordered接口。我将order参数设置为tx:annotation-driven order =“10”但它不起作用。
答案 0 :(得分:0)
“订单参数”是什么意思? Spring AOP中ordering advice支持的方式是@Ordered annotation或org.springframework.core.Ordered接口,它还定义了最高和最低优先级的常量。