Commit 41799c10f0c72bfc91e5b79f3e4df6e585cc5715
1 parent
25b114aa
修改数据源类型优先级,先根据方法,再根据类
Showing
2 changed files
with
9 additions
and
11 deletions
ruoyi/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
| 1 | 1 | package com.ruoyi.framework.aspectj; |
| 2 | 2 | |
| 3 | -import java.lang.reflect.Method; | |
| 3 | +import java.util.Objects; | |
| 4 | 4 | import org.aspectj.lang.ProceedingJoinPoint; |
| 5 | 5 | import org.aspectj.lang.annotation.Around; |
| 6 | 6 | import org.aspectj.lang.annotation.Aspect; |
| ... | ... | @@ -8,6 +8,7 @@ import org.aspectj.lang.annotation.Pointcut; |
| 8 | 8 | import org.aspectj.lang.reflect.MethodSignature; |
| 9 | 9 | import org.slf4j.Logger; |
| 10 | 10 | import org.slf4j.LoggerFactory; |
| 11 | +import org.springframework.core.annotation.AnnotationUtils; | |
| 11 | 12 | import org.springframework.core.annotation.Order; |
| 12 | 13 | import org.springframework.stereotype.Component; |
| 13 | 14 | import com.ruoyi.common.utils.StringUtils; |
| ... | ... | @@ -60,17 +61,12 @@ public class DataSourceAspect |
| 60 | 61 | public DataSource getDataSource(ProceedingJoinPoint point) |
| 61 | 62 | { |
| 62 | 63 | MethodSignature signature = (MethodSignature) point.getSignature(); |
| 63 | - Class<? extends Object> targetClass = point.getTarget().getClass(); | |
| 64 | - DataSource targetDataSource = targetClass.getAnnotation(DataSource.class); | |
| 65 | - if (StringUtils.isNotNull(targetDataSource)) | |
| 64 | + DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class); | |
| 65 | + if (Objects.nonNull(dataSource)) | |
| 66 | 66 | { |
| 67 | - return targetDataSource; | |
| 68 | - } | |
| 69 | - else | |
| 70 | - { | |
| 71 | - Method method = signature.getMethod(); | |
| 72 | - DataSource dataSource = method.getAnnotation(DataSource.class); | |
| 73 | 67 | return dataSource; |
| 74 | 68 | } |
| 69 | + | |
| 70 | + return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); | |
| 75 | 71 | } |
| 76 | 72 | } | ... | ... |
ruoyi/src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataSource.java