[英]Spring AOP, pointcut expressions : annotation with specific param
我有方法clear()
Aspect
类。
@Aspect
public class Clear
{
@After("@annotation(org.springframework.transaction.annotation.Transactional)")
public void clear()
{
// do smth
}
}
现在我希望在每次执行带有readOnly = true
注释@Transactional
的方法之后调用此方面
@Transactional(readOnly = true)
public void someMethod()
{
//...
}
没有自定义注释,有没有办法做到这一点?
我觉得你很亲密。
在clear
方法中,您应该接受JoinPoint
类型的参数。 Spring将在运行时自动填充此参数,您可以通过它获取特定连接点的详细信息,包括java.lang.reflect.Method
,它将包含您之后的注释。
我在想这样的事情:
@Aspect
public class Clear
{
@After("@annotation(org.springframework.transaction.annotation.Transactional)")
public void clear(final JoinPoint joinPoint)
{
final Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
final Transactional txAnnotation = methood.getAnnotation(Transactional.class);
final boolean isReadOnly = txAnnotation.readOnly();
//do conditional work based on isReadOnly
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.