Spring 带有 aspectj @annotation 的 AOP
Spring AOP with aspectj @annotation
我想使用 aspectJ 应用注释。 (使用Springboot 1.5.1, Mybatis 2.1.1)
所以,我制作了自定义注释和 AspectJ.. 并应用了它。
/** CustomAnnotation */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TestAnnotation {
String value();
}
/** AspectJ configuration */
@Component
@Aspect
public class AuditTrailAspect {
@Autowired
TestDAO dao;
@Around("@annotation(TestAnnotation)")
public Object doSomethingAround(ProceedingJoinPoint joinPoint) throws Throwable {
/* before proceed */
Object result = joinPoint.proceed();
/* after proceed */
return result;
}
}
/** Apply Annoataion at Repository */
@Repository
public interface TestDAO {
@TestAnnotation(value = "test")
int insertSomething(RequestDto dto);
}
(这段代码很简单,有问题)
如果应用切入点表达式'execution'此代码在 Repository(DAO) 中运行良好..
如果切入点表达式应用'@annotation',则此代码也适用于其他组件(服务..控制器)
但是,为什么我不能使用 AspectJ 在 Repository(DAO) 中应用自定义注释?
请帮助..谢谢!
无法继承已实现接口上的注释。
@Inherited 导致注释(仅在 class 上)从 superclasses 继承,但对接口实现没有影响。
Note that this meta-annotation type has no effect if the annotated
type is used to annotate anything other than a class. Note also that
this meta-annotation only causes annotations to be inherited from
superclasses; annotations on implemented interfaces have no effect.
我想使用 aspectJ 应用注释。 (使用Springboot 1.5.1, Mybatis 2.1.1)
所以,我制作了自定义注释和 AspectJ.. 并应用了它。
/** CustomAnnotation */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TestAnnotation {
String value();
}
/** AspectJ configuration */
@Component
@Aspect
public class AuditTrailAspect {
@Autowired
TestDAO dao;
@Around("@annotation(TestAnnotation)")
public Object doSomethingAround(ProceedingJoinPoint joinPoint) throws Throwable {
/* before proceed */
Object result = joinPoint.proceed();
/* after proceed */
return result;
}
}
/** Apply Annoataion at Repository */
@Repository
public interface TestDAO {
@TestAnnotation(value = "test")
int insertSomething(RequestDto dto);
}
(这段代码很简单,有问题)
如果应用切入点表达式'execution'此代码在 Repository(DAO) 中运行良好.. 如果切入点表达式应用'@annotation',则此代码也适用于其他组件(服务..控制器)
但是,为什么我不能使用 AspectJ 在 Repository(DAO) 中应用自定义注释? 请帮助..谢谢!
无法继承已实现接口上的注释。
@Inherited 导致注释(仅在 class 上)从 superclasses 继承,但对接口实现没有影响。
Note that this meta-annotation type has no effect if the annotated type is used to annotate anything other than a class. Note also that this meta-annotation only causes annotations to be inherited from superclasses; annotations on implemented interfaces have no effect.