多数据源支持类注解(允许继承父类的注解)
This commit is contained in:
@ -26,7 +26,8 @@ public class DataSourceAspect
|
||||
{
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)")
|
||||
@Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
|
||||
+ "|| @within(com.ruoyi.common.annotation.DataSource)")
|
||||
public void dsPointCut()
|
||||
{
|
||||
|
||||
@ -35,11 +36,7 @@ public class DataSourceAspect
|
||||
@Around("dsPointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable
|
||||
{
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
|
||||
Method method = signature.getMethod();
|
||||
|
||||
DataSource dataSource = method.getAnnotation(DataSource.class);
|
||||
DataSource dataSource = getDataSource(point);
|
||||
|
||||
if (StringUtils.isNotNull(dataSource))
|
||||
{
|
||||
@ -56,4 +53,24 @@ public class DataSourceAspect
|
||||
DynamicDataSourceContextHolder.clearDataSourceType();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要切换的数据源
|
||||
*/
|
||||
public DataSource getDataSource(ProceedingJoinPoint point)
|
||||
{
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Class<? extends Object> targetClass = point.getTarget().getClass();
|
||||
DataSource targetDataSource = targetClass.getAnnotation(DataSource.class);
|
||||
if (StringUtils.isNotNull(targetDataSource))
|
||||
{
|
||||
return targetDataSource;
|
||||
}
|
||||
else
|
||||
{
|
||||
Method method = signature.getMethod();
|
||||
DataSource dataSource = method.getAnnotation(DataSource.class);
|
||||
return dataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user