Skip to content

Commit fd1a8d7

Browse files
committed
修复配置多数据源切换BUG
1 parent 43e322d commit fd1a8d7

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

‎src/main/java/com/suke/czx/datasources/aspect/DataSourceAspect.java‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import com.suke.czx.datasources.DataSourceNames;
44
import com.suke.czx.datasources.DynamicDataSource;
55
import com.suke.czx.datasources.annotation.DataSource;
6+
import org.aspectj.lang.JoinPoint;
67
import org.aspectj.lang.ProceedingJoinPoint;
7-
import org.aspectj.lang.annotation.Around;
8-
import org.aspectj.lang.annotation.Aspect;
9-
import org.aspectj.lang.annotation.Before;
10-
import org.aspectj.lang.annotation.Pointcut;
8+
import org.aspectj.lang.annotation.*;
119
import org.aspectj.lang.reflect.MethodSignature;
1210
import org.slf4j.Logger;
1311
import org.slf4j.LoggerFactory;
@@ -33,7 +31,7 @@ public void dataSourcePointCut() {
3331
}
3432

3533
@Before("dataSourcePointCut()")
36-
public Object before(ProceedingJoinPoint point) throws Throwable {
34+
public void around(JoinPoint point) throws Throwable {
3735
MethodSignature signature = (MethodSignature) point.getSignature();
3836
Method method = signature.getMethod();
3937

@@ -45,13 +43,11 @@ public Object before(ProceedingJoinPoint point) throws Throwable {
4543
DynamicDataSource.setDataSource(ds.name());
4644
logger.debug("set datasource is " + ds.name());
4745
}
46+
}
4847

49-
try {
50-
return point.proceed();
51-
} finally {
52-
DynamicDataSource.clearDataSource();
53-
logger.debug("clean datasource");
54-
}
48+
@After("dataSourcePointCut()")
49+
public void after(){
50+
DynamicDataSource.clearDataSource();
5551
}
5652

5753
@Override

0 commit comments

Comments
 (0)