【发布时间】:2017-03-15 18:57:46
【问题描述】:
我在 maven 模块“A”中创建了下面的注释
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface CacheDelete {...}
在同一个模块“A”中,我有 TestPojo 类,我正在使用这个注解
@CacheDelete()
public void removeTestPojo(int id) {
}
我从模块“A”的测试用例中调用了这个 removeTestPojo() 方法。这里一切正常。我在我的建议中使用以下代码获得了正确的注释。
模块“A”中的建议方法代码CacheAspect类:
CacheDelete cacheDeleteAnnotation = getAnnotation((MethodSignature) joinPoint.getSignature(),
CacheDelete.class);
获取注解方法:
private <T extends Annotation> T getAnnotation(MethodSignature methodSignature,
Class<T> annotationClass) {
return methodSignature.getMethod().getAnnotation(annotationClass);
}
问题: 现在我有一个不同的模块“B”,我在其中使用“A”的依赖项,并且“B”模块中的一个方法用@CacheDelete 注释。
当我在模块“B”中为带注释的方法运行测试用例并调试 CacheAspect 类时,我的建议是调试点,但我的 get 注释在这里返回 null。 谁知道是什么原因?
【问题讨论】:
-
虽然这看起来很复杂,但我认为你应该提出一个minimal reproducible example。否则我们无能为力。
-
对我来说会有点复杂。我自己在这里工作是为了弄清楚:)
标签: java annotations aop