|
@@ -30,34 +30,64 @@ public class TargetDataSourceAspect {
|
|
|
@Before("dsPointCut()")
|
|
|
public void around(JoinPoint point) throws Throwable {
|
|
|
|
|
|
+ DataSourceManagement.flag.set("MASTER");
|
|
|
+ Integer type = switchDataSourceService.getType();
|
|
|
+
|
|
|
TargetDataSource annotation = null;
|
|
|
Class<? extends Object> target = point.getTarget().getClass();
|
|
|
if(target.isAnnotationPresent(TargetDataSource.class)){
|
|
|
// 判断类上是否标注着注解
|
|
|
annotation = target.getAnnotation(TargetDataSource.class);
|
|
|
log.info("类上标注了注解");
|
|
|
+
|
|
|
+ if ("SLAVE".equals(annotation.value().name())){
|
|
|
+ if(type != null && type == 1){
|
|
|
+ DataSourceManagement.flag.set(annotation.value().name());
|
|
|
+ System.out.println("type == 1==========================="+type+annotation.value().name()+"========================");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println(annotation.value().name()+type);
|
|
|
}else{
|
|
|
Method method = ((MethodSignature) point.getSignature()).getMethod();
|
|
|
if(method.isAnnotationPresent(TargetDataSource.class)){
|
|
|
// 判断方法上是否标注着注解,如果类和方法上都没有标注,则报错
|
|
|
annotation = method.getAnnotation(TargetDataSource.class);
|
|
|
log.info("方法上标注了注解");
|
|
|
+
|
|
|
+ if ("SLAVE".equals(annotation.value().name())){
|
|
|
+ if(type != null && type == 1){
|
|
|
+ DataSourceManagement.flag.set(annotation.value().name());
|
|
|
+ System.out.println("type == 1==========================="+type+annotation.value().name()+"========================");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println(annotation.value().name()+type);
|
|
|
}else{
|
|
|
throw new RuntimeException("@TargetDataSource注解只能用于类或者方法上, 错误出现在:[" +
|
|
|
target.toString() +" " + method.toString() + "];");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 切换数据源 0主数据源,1其他数据源
|
|
|
- SwitchDataSource switchDataSource = switchDataSourceService.getById(1);
|
|
|
- Integer type = Integer.valueOf(switchDataSource.getType());
|
|
|
- if (type != null && type == 0) {
|
|
|
- DataSourceManagement.flag.set("MASTER");
|
|
|
- System.out.println("==========================="+type+"MASTER========================");
|
|
|
- } else if (type != null && type == 1) {
|
|
|
- DataSourceManagement.flag.set(annotation.value().name());
|
|
|
- System.out.println("==========================="+type+annotation.value().name()+"========================");
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+// if ("SLAVE".equals(annotation.value().name())){
|
|
|
+// if(type != null && type == 1){
|
|
|
+// DataSourceManagement.flag.set(annotation.value().name());
|
|
|
+// System.out.println("type == 1==========================="+type+annotation.value().name()+"========================");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// System.out.println(annotation.value().name()+type);
|
|
|
+
|
|
|
+// // 切换数据源 0主数据源,1其他数据源
|
|
|
+// Integer type = switchDataSourceService.getType();
|
|
|
+//// SwitchDataSource switchDataSource = switchDataSourceService.getById(1);
|
|
|
+//// Integer type = Integer.valueOf(switchDataSource.getType());
|
|
|
+// if (type != null && type == 0) {
|
|
|
+// DataSourceManagement.flag.set("MASTER");
|
|
|
+// System.out.println("type == 0==========================="+type+"MASTER========================");
|
|
|
+// } else if (type != null && type == 1) {
|
|
|
+// DataSourceManagement.flag.set(annotation.value().name());
|
|
|
+// System.out.println("type == 1==========================="+type+annotation.value().name()+"========================");
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
}
|