自定义注解拦截器代码实现
获取某个类或者方法是否有自定义注解demo
seata 2.3.0 GlobalTransactionalInterceptorParser
protected boolean existsAnnotation(Class<?>... classes) {
boolean result = false;
if (CollectionUtils.isNotEmpty(classes)) {
for (Class<?> clazz : classes) {
if (clazz == null) {
continue;
}
GlobalTransactional trxAnno = clazz.getAnnotation(GlobalTransactional.class);
if (trxAnno != null) {
return true;
}
Method[] methods = clazz.getMethods();
for (Method method : methods) {
trxAnno = method.getAnnotation(GlobalTransactional.class);
if (trxAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
GlobalLock lockAnno = method.getAnnotation(GlobalLock.class);
if (lockAnno != null) {
methodsToProxy.add(method.getName());
result = true;
}
}
}
}
return result;
}

浙公网安备 33010602011771号