From cdfd0e963d66721dfb0410598002273f7d26bc89 Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期一, 07 四月 2025 17:56:20 +0800 Subject: [PATCH] zjh20250407 --- ltkj-framework/src/main/java/com/ltkj/framework/aspectj/AsynAspect.java | 46 +++++++++++++++++----------------------------- 1 files changed, 17 insertions(+), 29 deletions(-) diff --git a/ltkj-framework/src/main/java/com/ltkj/framework/aspectj/AsynAspect.java b/ltkj-framework/src/main/java/com/ltkj/framework/aspectj/AsynAspect.java index 1993ebf..805a023 100644 --- a/ltkj-framework/src/main/java/com/ltkj/framework/aspectj/AsynAspect.java +++ b/ltkj-framework/src/main/java/com/ltkj/framework/aspectj/AsynAspect.java @@ -1,62 +1,50 @@ package com.ltkj.framework.aspectj; -import com.ltkj.common.annotation.DataSource; -import com.ltkj.common.utils.StringUtils; import com.ltkj.db.DataSourceContextHolder; import com.ltkj.framework.datasource.DynamicDataSourceContextHolder; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; -import org.aspectj.lang.reflect.MethodSignature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; - -import java.util.Objects; /** * ClassName: AsynAspect <br/> - * Description: <br/> + * Description: 鍦ㄥ紓姝ユ柟娉曟墽琛屾椂锛岃幏鍙栧苟浼犻�掑綋鍓嶇嚎绋嬬殑鏁版嵁婧愩��<br/> * date: 2025/2/15 18:07<br/> * * @author zjh<br /> */ -@Aspect -@Order(2) -@Component +//@Aspect +//@Component public class AsynAspect { - protected Logger logger = LoggerFactory.getLogger(getClass()); + private static final Logger logger = LoggerFactory.getLogger(AsynAspect.class); - @Pointcut("@annotation(org.springframework.scheduling.annotation.Async)" - + "|| @within(org.springframework.scheduling.annotation.Async)") - public void dsPointCut() { - + @Pointcut("@annotation(org.springframework.scheduling.annotation.Async) || @within(org.springframework.scheduling.annotation.Async)") + public void asyncPointCut() { + // 寮傛鏂规硶鍒囧叆鐐� } - @Around("dsPointCut()") + @Around("asyncPointCut()") public Object around(ProceedingJoinPoint point) throws Throwable { - String key = DataSourceContextHolder.getDataSourceKey(); - logger.info("鎵ц涔嬪墠"); - logger.info("DataSourceContextHolder ->{}",key); - logger.info("DynamicDataSourceContextHolder ->{}", DynamicDataSourceContextHolder.getDataSourceType()); + // 鑾峰彇褰撳墠绾跨▼鐨� DataSource + String currentDataSource = DataSourceContextHolder.getDataSourceKey(); - DynamicDataSourceContextHolder.setDataSourceType(key); + logger.info("褰撳墠绾跨▼鏁版嵁婧�: {}", currentDataSource); + + // 鍦ㄥ紓姝ユ柟娉曟墽琛屽墠锛岃缃暟鎹簮鍒� DynamicDataSourceContextHolder + DynamicDataSourceContextHolder.setDataSourceType(currentDataSource); try { + // 鎵ц寮傛鏂规硶 return point.proceed(); } finally { - logger.info("鎵ц涔嬪悗"); - logger.info("DataSourceContextHolder ->{}",key); - logger.info("DynamicDataSourceContextHolder ->{}",DynamicDataSourceContextHolder.getDataSourceType()); - // 閿�姣佹暟鎹簮 鍦ㄦ墽琛屾柟娉曚箣鍚� + // 鎵ц瀹屾瘯鍚庢竻鐞嗘暟鎹簮 DynamicDataSourceContextHolder.clearDataSourceType(); - logger.info("鎵ц涔嬪悗 clear涔嬪悗"); - logger.info("DataSourceContextHolder ->{}",key); - logger.info("DynamicDataSourceContextHolder ->{}",DynamicDataSourceContextHolder.getDataSourceType()); + logger.info("娓呯悊鏁版嵁婧愶紝鎭㈠榛樿鏁版嵁婧�"); } } } -- Gitblit v1.8.0