rsf-open-api/src/main/java/com/vincent/rsf/openApi/common/datasource/UseDataSourceAspect.java
@@ -4,9 +4,12 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.aop.support.AopUtils; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.util.ClassUtils; import java.lang.reflect.Method; @@ -33,13 +36,15 @@ } private UseDataSource resolveAnnotation(ProceedingJoinPoint joinPoint) { Object target = joinPoint.getTarget(); Class<?> userClass = ClassUtils.getUserClass(target); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); UseDataSource annotation = method.getAnnotation(UseDataSource.class); if (annotation != null) { return annotation; Method specific = AopUtils.getMostSpecificMethod(method, userClass); UseDataSource onMethod = AnnotationUtils.findAnnotation(specific, UseDataSource.class); if (onMethod != null) { return onMethod; } Class<?> targetClass = joinPoint.getTarget().getClass(); return targetClass.getAnnotation(UseDataSource.class); return AnnotationUtils.findAnnotation(userClass, UseDataSource.class); } } rsf-server/src/main/java/com/vincent/rsf/server/common/datasource/UseDataSourceAspect.java
@@ -4,9 +4,12 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.aop.support.AopUtils; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.util.ClassUtils; import java.lang.reflect.Method; @@ -33,14 +36,16 @@ } private UseDataSource resolveAnnotation(ProceedingJoinPoint joinPoint) { Object target = joinPoint.getTarget(); Class<?> userClass = ClassUtils.getUserClass(target); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); UseDataSource annotation = method.getAnnotation(UseDataSource.class); if (annotation != null) { return annotation; Method specific = AopUtils.getMostSpecificMethod(method, userClass); UseDataSource onMethod = AnnotationUtils.findAnnotation(specific, UseDataSource.class); if (onMethod != null) { return onMethod; } Class<?> targetClass = joinPoint.getTarget().getClass(); return targetClass.getAnnotation(UseDataSource.class); return AnnotationUtils.findAnnotation(userClass, UseDataSource.class); } }