假设有一个类Object bean(是动态代理类)
1、通过以下方式获取不到注解,得到的mapping是空
Class<?> clazz = bean.getClass();
Method[] ms = clazz.getMethods();
for (Method m : ms) {
//获取Action注解
Action mapping = m.getAnnotation(Action.class);
}
2、用如下方式获取,此时可以得到注解Action,mapping不再是空
Method[] ms = ReflectionUtils.getAllDeclaredMethods(AopUtils.getTargetClass(bean));
for (Method m : ms) {
Action mapping = AnnotationUtils.findAnnotation(m, Action.class);
}