如何使用AspectJ进行Spring持久性异常翻译

时间:2011-07-22 09:53:03

标签: java spring jpa aop aspectj

我使用带有AspectJ的Spring 3.0,比使用AspectJ更多地使用AOP Proxies。 这种接缝几乎适用于所有关注点,但不适用于持久性异常翻译。 - 我的问题是如何使用AspectJ进行持久性异常转换而不是Spring JDK AOP代理?

我配置的相关部分是:

 <context:spring-configured/>
 ...
 <context:component-scan />
 ....
 <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />   

1 个答案:

答案 0 :(得分:1)

如果您针对spring-aspects.jar进行编译,那么这应该是开箱即用的。请参阅org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect以供参考。也许它的切入点不能涵盖您的场景,在这种情况下,您需要使用自己的切入点扩展方面。以下是标准切入点:

pointcut entityManagerCall(): call(* EntityManager.*(..))
    || call(* EntityManagerFactory.*(..))
    || call(* EntityTransaction.*(..))
    || call(* Query.*(..));