You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ra...@apache.org on 2021/04/22 01:58:41 UTC
[dubbo-spi-extensions] branch 2.7.x updated: Do not get dubbo
ProviderConfig config when ServiceConfig not set group (#24)
This is an automated email from the ASF dual-hosted git repository.
ranke pushed a commit to branch 2.7.x
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git
The following commit(s) were added to refs/heads/2.7.x by this push:
new 12d9f0a Do not get dubbo ProviderConfig config when ServiceConfig not set group (#24)
12d9f0a is described below
commit 12d9f0a0eca425580ef6fe8751e09dc9335411d6
Author: wangzhen <wa...@msn.com>
AuthorDate: Thu Apr 22 09:58:32 2021 +0800
Do not get dubbo ProviderConfig config when ServiceConfig not set group (#24)
* fix not get dubbo ProviderConfig config when ServiceConfig not set group
* fix not get dubbo ProviderConfig config when ServiceConfig not set group
---
.../core/DubboApiDocsAnnotationScanner.java | 49 +++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java b/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java
index 6cd8b07..98cc520 100644
--- a/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java
+++ b/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java
@@ -29,6 +29,7 @@ import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.apidocs.annotations.ApiModule;
@@ -95,6 +96,9 @@ public class DubboApiDocsAnnotationScanner implements ApplicationListener<Applic
@Autowired
private ProtocolConfig protocol;
+ @Autowired(required = false)
+ private ProviderConfig providerConfig;
+
@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
// Register dubbo doc provider
@@ -132,8 +136,15 @@ public class DubboApiDocsAnnotationScanner implements ApplicationListener<Applic
apiVersion = dubboService.version();
apiGroup = dubboService.group();
}
+
+
+ // API version&group safe guard!
+ apiVersion = getApiVersionIfAbsent(apiVersion);
+ apiGroup = getApiGroupIfAbsent(apiGroup);
+
apiVersion = applicationContext.getEnvironment().resolvePlaceholders(apiVersion);
apiGroup = applicationContext.getEnvironment().resolvePlaceholders(apiGroup);
+
ModuleCacheItem moduleCacheItem = new ModuleCacheItem();
DubboApiDocsCache.addApiModule(moduleAnn.apiInterface().getCanonicalName(), moduleCacheItem);
//module name
@@ -158,6 +169,42 @@ public class DubboApiDocsAnnotationScanner implements ApplicationListener<Applic
LOG.info("================= Dubbo API Docs-- doc annotations scanning and processing completed ================");
}
+ /**
+ * get provider config(default) api version if param apiVersion is blank
+ * @param apiVersion api version
+ * @return api version is apiVersion when it isn`t blank, or return provider config(default) version
+ */
+ private String getApiVersionIfAbsent(String apiVersion) {
+ if (StringUtils.isBlank(apiVersion)) {
+ if (providerConfig != null) {
+ apiVersion = providerConfig.getVersion();
+ }
+
+ if (StringUtils.isBlank(apiVersion)) {
+ apiVersion = "";
+ }
+ }
+ return apiVersion;
+ }
+
+ /**
+ * get provider config(default) api group if param apiGroup is blank
+ * @param apiGroup api version
+ * @return api group is apiGroup when it isn`t blank, or return provider config(default) group
+ */
+ private String getApiGroupIfAbsent(String apiGroup) {
+ if (StringUtils.isBlank(apiGroup)) {
+ if (providerConfig != null) {
+ apiGroup = providerConfig.getGroup();
+ }
+
+ if (StringUtils.isBlank(apiGroup)) {
+ apiGroup = "";
+ }
+ }
+ return apiGroup;
+ }
+
private void processApiDocAnnotation(Method method, List<ApiCacheItem> moduleApiList, ApiModule moduleAnn,
boolean async, ModuleCacheItem moduleCacheItem, String apiVersion, String apiGroup) {
@@ -272,7 +319,7 @@ public class DubboApiDocsAnnotationScanner implements ApplicationListener<Applic
genericTypeAndNamesMap = Collections.EMPTY_MAP;
}
- List<ParamBean> apiParamsList = new ArrayList(16);
+ List<ParamBean> apiParamsList = new ArrayList<>(16);
// get all fields
List<Field> allFields = ClassTypeUtil.getAllFields(null, argClass);
if (allFields.size() > 0) {