我有一个方面与带有注释的方法相匹配(否则这个代码不会被调用),现在我使用org.springframework.core.annotation.AnnotationUtils来获取注释,但这给了我一个nullPointerException在我在tomcat中运行应用程序的最后一行。它在单元测试中工作正常。
before() : runWithContext() {
MethodSignature methodSignature = (MethodSignature) thisJoinPoint
.getSignature();
Method targetMethod = methodSignature.getMethod();
RunWithContext anno = AnnotationUtils.getAnnotation(targetMethod, RunWithContext.class);
ContextInvocationUtils.replaceContext(anno.someValue());
}
tomcat以及单元测试启动一个spring-container与我编织代码所在的位置完全相同(它是spring-integration出站通道适配器的消息处理程序)
我的注释看起来像这样
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE})
@Inherited
public @interface RunWithContext {
String[] authorities() default {};
}
编辑:
调用targetMethod.getAnnotation有效,任何提示是什么org.springframework.core.annotation.AnnotationUtils.getAnnotation(Method,Class)如果在我的情况下没有正确地给我注释?