Skip to content

Commit cdc1033

Browse files
committed
fix: spring xml配置文件可配置 async-mode
1 parent 954be44 commit cdc1033

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

forest-core/src/main/java/com/dtflys/forest/config/ForestConfiguration.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -716,26 +716,6 @@ public ForestConfiguration setAsyncMode(ForestAsyncMode asyncMode) {
716716
return this;
717717
}
718718

719-
/**
720-
* 设置异步模式
721-
*
722-
* @param asyncMode 异步模式 - 字符串
723-
* @return 当前ForestConfiguration实例
724-
* @since 1.5.27
725-
*/
726-
public ForestConfiguration setAsyncMode(String asyncMode) {
727-
if (StringUtils.isEmpty(asyncMode)) {
728-
throw new ForestRuntimeException("Can not resolve async mode '" + asyncMode + "'");
729-
}
730-
final String enumName = asyncMode.trim().toUpperCase();
731-
ForestAsyncMode mode = ForestAsyncMode.valueOf(enumName);
732-
if (mode == null) {
733-
throw new ForestRuntimeException("Can not resolve async mode '" + enumName + "'");
734-
}
735-
this.asyncMode = mode;
736-
return this;
737-
}
738-
739719
/**
740720
* 获取最大异步线程池队列大小
741721
*

forest-spring/src/main/java/com/dtflys/forest/schema/ForestConfigurationBeanDefinitionParser.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dtflys.forest.schema;
22

3+
import com.dtflys.forest.http.ForestAsyncMode;
34
import com.dtflys.forest.interceptor.SpringInterceptorFactory;
45
import com.dtflys.forest.logging.ForestLogHandler;
56
import com.dtflys.forest.reflection.SpringForestObjectFactory;
@@ -83,8 +84,17 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
8384
if (StringUtils.isNotEmpty(attributeValue)) {
8485
if ("backend".equals(attributeName)) {
8586
beanDefinition.getPropertyValues().addPropertyValue("backendName", attributeValue);
86-
}
87-
else if ("logHandler".equals(attributeName)) {
87+
} else if ("asyncMode".equals(attributeName)) {
88+
if (StringUtils.isEmpty(attributeValue)) {
89+
throw new ForestRuntimeException("Can not resolve async mode '" + attributeValue + "'");
90+
}
91+
final String enumName = attributeValue.trim().toUpperCase();
92+
ForestAsyncMode mode = ForestAsyncMode.valueOf(enumName);
93+
if (mode == null) {
94+
throw new ForestRuntimeException("Can not resolve async mode '" + enumName + "'");
95+
}
96+
beanDefinition.getPropertyValues().addPropertyValue("asyncMode", mode);
97+
} else if ("logHandler".equals(attributeName)) {
8898
try {
8999
Class clazz = Class.forName(attributeValue);
90100
if (!ForestLogHandler.class.isAssignableFrom(clazz)) {

forest-spring/src/test/java/com/dtflys/spring/test/ClientTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.dtflys.forest.Forest;
44
import com.dtflys.forest.config.ForestConfiguration;
5+
import com.dtflys.forest.http.ForestAsyncMode;
56
import com.dtflys.spring.test.client2.GithubClient;
67
import junit.framework.TestCase;
78
import com.dtflys.spring.test.client0.BeastshopClient;
@@ -35,6 +36,7 @@ public void testScan() {
3536
assertThat(configuration.getMaxRequestQueueSize()).isEqualTo(300);
3637
assertThat(configuration.getMaxAsyncThreadSize()).isEqualTo(256);
3738
assertThat(configuration.getMaxAsyncQueueSize()).isEqualTo(128);
39+
assertThat(configuration.getAsyncMode()).isEqualTo(ForestAsyncMode.KOTLIN_COROUTINE);
3840
Object baseUrl = configuration.getVariableValue("baseUrl");
3941
assertThat(baseUrl).isNotNull().isEqualTo("http://www.thebeastshop.com");
4042
}

0 commit comments

Comments
 (0)