我正在尝试创建自定义注释以便快捷方式,就像在文档中引用一样:
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional("order")
public @interface OrderTx {
}
No hibernate session bound to thread,and configuration does not allow creation…
由于我正在注释的方法不属于从应用程序上下文实例化的Bean,我的猜测是AnnotationTransactionAspect不能使用自定义注释,并且AOP魔法不起作用.
如何获得快捷方式的自定义注释并在任何地方工作?
我错过了别的什么吗?
最佳答案
以下是AnnotationTransactionAspect中使用的切入点:
原文链接:https://www.f2er.com/spring/432285.html/**
* Matches the execution of any public method in a type with the
* Transactional annotation,or any subtype of a type with the
* Transactional annotation.
*/
private pointcut executionOfAnyPublicMethodInAtTransactionalType() :
execution(public * ((@Transactional *)+).*(..)) && @this(Transactional);
/**
* Matches the execution of any method with the
* Transactional annotation.
*/
private pointcut executionOfTransactionalMethod() :
execution(* *(..)) && @annotation(Transactional);
我会说非常清楚元注释不匹配(我甚至不认为有一个有效的aspectj切入点可以捕获元注释).所以我想你必须继承AbstractTransactionAspect并为这个切入点提供你自己的实现来捕获你的自定义注释:
/**
* Concrete subaspects must implement this pointcut,to identify
* transactional methods. For each selected joinpoint,TransactionMetadata
* will be retrieved using Spring's TransactionAttributeSource interface.
*/
protected abstract pointcut transactionalMethodExecution(Object txObject);