From cdc103369f0457eb7acd83946ce91455a8cbbc4d Mon Sep 17 00:00:00 2001 From: dt_flys Date: Tue, 22 Nov 2022 00:29:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20spring=20xml=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8F=AF=E9=85=8D=E7=BD=AE=20async-mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/config/ForestConfiguration.java | 20 ------------------- ...restConfigurationBeanDefinitionParser.java | 14 +++++++++++-- .../com/dtflys/spring/test/ClientTest.java | 2 ++ 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/forest-core/src/main/java/com/dtflys/forest/config/ForestConfiguration.java b/forest-core/src/main/java/com/dtflys/forest/config/ForestConfiguration.java index 5d5f31abc..ec61dc091 100644 --- a/forest-core/src/main/java/com/dtflys/forest/config/ForestConfiguration.java +++ b/forest-core/src/main/java/com/dtflys/forest/config/ForestConfiguration.java @@ -716,26 +716,6 @@ public ForestConfiguration setAsyncMode(ForestAsyncMode asyncMode) { return this; } - /** - * 设置异步模式 - * - * @param asyncMode 异步模式 - 字符串 - * @return 当前ForestConfiguration实例 - * @since 1.5.27 - */ - public ForestConfiguration setAsyncMode(String asyncMode) { - if (StringUtils.isEmpty(asyncMode)) { - throw new ForestRuntimeException("Can not resolve async mode '" + asyncMode + "'"); - } - final String enumName = asyncMode.trim().toUpperCase(); - ForestAsyncMode mode = ForestAsyncMode.valueOf(enumName); - if (mode == null) { - throw new ForestRuntimeException("Can not resolve async mode '" + enumName + "'"); - } - this.asyncMode = mode; - return this; - } - /** * 获取最大异步线程池队列大小 * diff --git a/forest-spring/src/main/java/com/dtflys/forest/schema/ForestConfigurationBeanDefinitionParser.java b/forest-spring/src/main/java/com/dtflys/forest/schema/ForestConfigurationBeanDefinitionParser.java index 7c6a73f4d..87cc68e7e 100644 --- a/forest-spring/src/main/java/com/dtflys/forest/schema/ForestConfigurationBeanDefinitionParser.java +++ b/forest-spring/src/main/java/com/dtflys/forest/schema/ForestConfigurationBeanDefinitionParser.java @@ -1,5 +1,6 @@ package com.dtflys.forest.schema; +import com.dtflys.forest.http.ForestAsyncMode; import com.dtflys.forest.interceptor.SpringInterceptorFactory; import com.dtflys.forest.logging.ForestLogHandler; import com.dtflys.forest.reflection.SpringForestObjectFactory; @@ -83,8 +84,17 @@ public BeanDefinition parse(Element element, ParserContext parserContext) { if (StringUtils.isNotEmpty(attributeValue)) { if ("backend".equals(attributeName)) { beanDefinition.getPropertyValues().addPropertyValue("backendName", attributeValue); - } - else if ("logHandler".equals(attributeName)) { + } else if ("asyncMode".equals(attributeName)) { + if (StringUtils.isEmpty(attributeValue)) { + throw new ForestRuntimeException("Can not resolve async mode '" + attributeValue + "'"); + } + final String enumName = attributeValue.trim().toUpperCase(); + ForestAsyncMode mode = ForestAsyncMode.valueOf(enumName); + if (mode == null) { + throw new ForestRuntimeException("Can not resolve async mode '" + enumName + "'"); + } + beanDefinition.getPropertyValues().addPropertyValue("asyncMode", mode); + } else if ("logHandler".equals(attributeName)) { try { Class clazz = Class.forName(attributeValue); if (!ForestLogHandler.class.isAssignableFrom(clazz)) { diff --git a/forest-spring/src/test/java/com/dtflys/spring/test/ClientTest.java b/forest-spring/src/test/java/com/dtflys/spring/test/ClientTest.java index d30818ff2..93bc590cf 100644 --- a/forest-spring/src/test/java/com/dtflys/spring/test/ClientTest.java +++ b/forest-spring/src/test/java/com/dtflys/spring/test/ClientTest.java @@ -2,6 +2,7 @@ import com.dtflys.forest.Forest; import com.dtflys.forest.config.ForestConfiguration; +import com.dtflys.forest.http.ForestAsyncMode; import com.dtflys.spring.test.client2.GithubClient; import junit.framework.TestCase; import com.dtflys.spring.test.client0.BeastshopClient; @@ -35,6 +36,7 @@ public void testScan() { assertThat(configuration.getMaxRequestQueueSize()).isEqualTo(300); assertThat(configuration.getMaxAsyncThreadSize()).isEqualTo(256); assertThat(configuration.getMaxAsyncQueueSize()).isEqualTo(128); + assertThat(configuration.getAsyncMode()).isEqualTo(ForestAsyncMode.KOTLIN_COROUTINE); Object baseUrl = configuration.getVariableValue("baseUrl"); assertThat(baseUrl).isNotNull().isEqualTo("http://www.thebeastshop.com"); }