From ac9e3f2ca4d2255739f8b60165f5b51b31ccd3e6 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 13 一月 2023 23:04:08 +0800 Subject: [PATCH] update 适配 springdoc 新版本配置方式 --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/AsyncConfig.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/AsyncConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/AsyncConfig.java new file mode 100644 index 0000000..e752743 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/AsyncConfig.java @@ -0,0 +1,54 @@ +package com.ruoyi.framework.config; + +import cn.hutool.core.util.ArrayUtil; +import com.ruoyi.common.exception.ServiceException; +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.AsyncConfigurer; +import org.springframework.scheduling.annotation.EnableAsync; + +import java.util.Arrays; +import java.util.concurrent.Executor; +import java.util.concurrent.ScheduledExecutorService; + +/** + * 寮傛閰嶇疆 + * + * @author Lion Li + */ +@EnableAsync(proxyTargetClass = true) +@Configuration +public class AsyncConfig implements AsyncConfigurer { + + @Autowired + @Qualifier("scheduledExecutorService") + private ScheduledExecutorService scheduledExecutorService; + + /** + * 鑷畾涔� @Async 娉ㄨВ浣跨敤绯荤粺绾跨▼姹� + */ + @Override + public Executor getAsyncExecutor() { + return scheduledExecutorService; + } + + /** + * 寮傛鎵ц寮傚父澶勭悊 + */ + @Override + public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + return (throwable, method, objects) -> { + throwable.printStackTrace(); + StringBuilder sb = new StringBuilder(); + sb.append("Exception message - ").append(throwable.getMessage()) + .append(", Method name - ").append(method.getName()); + if (ArrayUtil.isNotEmpty(objects)) { + sb.append(", Parameter value - ").append(Arrays.toString(objects)); + } + throw new ServiceException(sb.toString()); + }; + } + +} -- Gitblit v1.9.3