【发布时间】:2021-09-03 09:24:03
【问题描述】:
我想用 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);
}
(这个代码很简单,有问题)
如果切入点表达式应用“执行”,则此代码在 Repository(DAO) 中运行良好。 如果切入点表达式应用'@annotation',此代码也适用于其他组件(服务..控制器)
但是,为什么我不能使用 AspectJ 在 Repository(DAO) 中应用自定义注释? 请帮忙..谢谢!
【问题讨论】:
标签: model-view-controller aop aspectj