From eca2be1a2e5b73c7946509849e3f526348793786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 12 Jan 2024 10:24:00 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20Async=20=E9=92=88?= =?UTF-8?q?=E5=AF=B9=E8=99=9A=E6=8B=9F=E7=BA=BF=E7=A8=8B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=20=E4=B8=8E=E5=85=B6=E4=BB=96=E6=B3=A8=E6=84=8F=E4=BA=8B?= =?UTF-8?q?=E9=A1=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/src/main/resources/application.yml | 1 + .../org/dromara/common/core/config/ApplicationConfig.java | 2 ++ .../java/org/dromara/common/core/config/AsyncConfig.java | 6 ++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 265e1ef1b..37e073463 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -231,6 +231,7 @@ xss: urlPatterns: /system/*,/monitor/*,/tool/* # 全局线程池相关配置 +# 如使用JDK21请直接使用虚拟线程 不要开启此配置 thread-pool: # 是否开启线程池 enabled: false diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ApplicationConfig.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ApplicationConfig.java index 07500ba1b..d12008706 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ApplicationConfig.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ApplicationConfig.java @@ -2,6 +2,7 @@ package org.dromara.common.core.config; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.scheduling.annotation.EnableAsync; /** * 程序注解配置 @@ -11,6 +12,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; @AutoConfiguration // 表示通过aop框架暴露该代理对象,AopContext能够访问 @EnableAspectJAutoProxy(exposeProxy = true) +@EnableAsync(proxyTargetClass = true) public class ApplicationConfig { } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/AsyncConfig.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/AsyncConfig.java index 9a32afe55..66eea66ce 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/AsyncConfig.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/AsyncConfig.java @@ -5,18 +5,20 @@ import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.SpringUtils; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.AsyncConfigurer; -import org.springframework.scheduling.annotation.EnableAsync; import java.util.Arrays; import java.util.concurrent.Executor; /** * 异步配置 + *

+ * 如果未使用虚拟线程则生效 * * @author Lion Li */ -@EnableAsync(proxyTargetClass = true) +@ConditionalOnProperty(prefix = "spring.threads.virtual", name = "enabled", havingValue = "false") @AutoConfiguration public class AsyncConfig implements AsyncConfigurer {