i have an annotation in my app
@Trans
that i would like AOP to intercept and manage the transaction for. is there a tutorial out there that can tell me how to do this in spring 3? 开发者_C百科
You're reinventing the @Transactional
annotation of Spring. Read http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#transaction-declarative-annotations
If you have your own annotation called @Trans
, or if you meant Spring's own @Transactional
annotation, you can use the @within
Pointcut Designator.
From Spring's AOP documentation:
@within - limits matching to join points within types that have the given annotation (the execution of methods declared in types with the given annotation when using Spring AOP)
and
any join point (method execution only in Spring AOP) where the declared type of the target object has an @Transactional annotation:
@within(org.springframework.transaction.annotation.Transactional)
So using this advice, you can create a Pointcut around all methods that have the annotation you specify.
Also, this is a similar question, you may find it helpful:
AOP pointcut expression for any public method of a service
精彩评论