You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/06/01 07:02:47 UTC

[servicecomb-docs] branch master updated: [SCB-1973]fix problem in file download and config document

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-docs.git


The following commit(s) were added to refs/heads/master by this push:
     new 833129c  [SCB-1973]fix problem in file download and config document
833129c is described below

commit 833129ca039f5f26f295adc733888574e7eccc1a
Author: liubao <bi...@qq.com>
AuthorDate: Mon Jun 1 14:58:04 2020 +0800

    [SCB-1973]fix problem in file download and config document
---
 .../zh_CN/docs/config/inject-config.md             | 175 +++++++++++----------
 .../docs/general-development/file-download.md      |   4 +
 2 files changed, 94 insertions(+), 85 deletions(-)

diff --git a/java-chassis-reference/zh_CN/docs/config/inject-config.md b/java-chassis-reference/zh_CN/docs/config/inject-config.md
index c2c34ad..18dfb7c 100644
--- a/java-chassis-reference/zh_CN/docs/config/inject-config.md
+++ b/java-chassis-reference/zh_CN/docs/config/inject-config.md
@@ -8,93 +8,98 @@ Bean 属性对应的配置项名称支持通配符, 一个属性可以关联
 Java Bean,或是一个拥有public字段的类。
 
 ## 配置注入对象
+
 我们首先设计两个Java类用于注入配置属性,分别用来演示不使用注解和使用注解的场景。
 
-```Java
-/*
-使用ServiceComb注解
-*/
-@InjectProperties(prefix = "root") //指定该model关联的配置属性的前缀
-public class ConfigWithAnnotation {
-
-  /*
-	此处的prefix属性值"override"会覆盖标注在类定义的@InjectProperties注解的prefix属性值"root",keys属性可以为一个字符串数组并且数组元素下标越小优先级越高
-	这里会按照如下顺序的属性名称查找配置属性,直到找到已被配置的配置属性,则停止查找:
-	1)override.high
-    2)override.low
-	*/
-  @InjectProperty(prefix = "override", keys = {"high", "low"})
-  public String strValue;
-
-  //keys支持通配符,并在可以在将配置属性注入的时候指定通配符的代入对象。
-  @InjectProperty(keys = "${key}.value")
-  public int intValue;
-
-	//通配符的代入对象可以是一个字符串List,优先级遵循数组元素下标越小优先级越高策略
-	@InjectProperty(keys = "${full-list}")
-  public float floatValue;
-
-  //keys属性也支持多个通配符,优先级如下:首先通配符的优先级从左到右递减,然后如果通配符被代入List,遵循List中元素index越小优先级越高策略。
-  @InjectProperty(keys = "${low-list}.a.${high-list}.b")
-  public long longValue;
-
-	//可以通过注解的defaultValue属性指定默认值。如果字段未关联任何配置属性,定义的默认值会生效,否则默认值会被覆盖
-  @InjectProperty(defaultValue = "abc")
-  public String strDef;
-
-}
-```
-
-```Java
-/*
-不使用ServiceComb注解
-*/
-public class ConfigNoAnnotation {
-    /*
-	如果未提供@InjectProperties和@InjectProperty注解,会默认使用字段名作为配置属性名。注意类名不作为前缀起作用。
-	此处将配置属性 strValue 绑定到该字段
-	*/
-  public String strValue;
-}
-```
+* 使用注解
+
+        ```Java
+        @InjectProperties(prefix = "root") //指定该model关联的配置属性的前缀
+        public class ConfigWithAnnotation {
+        
+          /*
+            此处的prefix属性值"override"会覆盖标注在类定义的@InjectProperties注解的prefix属性值"root",keys属性可以为一个字符串数组,
+            下标越小优先级越高。
+            这里会按照如下顺序的属性名称查找配置属性,直到找到已被配置的配置属性,则停止查找:
+            1)override.high
+            2)override.low
+          */
+          @InjectProperty(prefix = "override", keys = {"high", "low"})
+          public String strValue;
+        
+          //keys支持通配符,并在可以在将配置属性注入的时候指定通配符的代入对象。
+          @InjectProperty(keys = "${key}.value")
+          public int intValue;
+        
+            //通配符的代入对象可以是一个字符串List,优先级遵循数组元素下标越小优先级越高策略
+           @InjectProperty(keys = "${full-list}")
+           public float floatValue;
+        
+          //keys属性也支持多个通配符,优先级如下:首先通配符的优先级从左到右递减,然后如果通配符被代入List,遵循List中元素index越小优先级越高策略。
+          @InjectProperty(keys = "${low-list}.a.${high-list}.b")
+          public long longValue;
+        
+            //可以通过注解的defaultValue属性指定默认值。如果字段未关联任何配置属性,定义的默认值会生效,否则默认值会被覆盖
+          @InjectProperty(defaultValue = "abc")
+          public String strDef;
+        
+        }
+        ```
+
+* 不使用注解
+
+        ```Java
+        public class ConfigNoAnnotation {
+            /*
+            如果未提供@InjectProperties和@InjectProperty注解,会默认使用字段名作为配置属性名。注意类名不作为前缀起作用。
+            此处将配置属性 strValue 绑定到该字段
+            */
+          public String strValue;
+        }
+        ```
 
 ## 执行注入
-我们可以通过以下示例代码来执行注入:
-
-将配置属性注入到无`@InjectProperties`和`@InjectProperty`注解的对象上:
-
-```Java
-ConfigNoAnnotation config = SCBEngine.getInstance().getPriorityPropertyManager().createConfigObject(ConfigNoAnnotation.class);
-```
-
-将配置属性注入到有`@InjectProperties`和`@InjectProperty`注解的对象上:
-
-* 将名称为root.k.value的配置属性注入到一个ConfigWithAnnotation对象的intValue字段
-
-* ConfigWithAnnotation对象的longValue字段按以下顺序查找已配置的配置属性进行注入:
-  1.  root.low-1.a.high-1.b
-  2.  root.low-1.a.high-2.b
-  3.  root.low-2.a.high-1.b
-  4.  root.low-2.a.high-2.b
-
-* ConfigWithAnnotation对象的floatValue字段按以下顺序查找已配置的配置属性进行注入:
-  1.  root.l1-1
-  2.  root.l1-2
-
-```Java
-ConfigWithAnnotation config = SCBEngine.getInstance().getPriorityPropertyManager()
-  .createConfigObject(ConfigWithAnnotation.class,
-        "key", "k",
-        "low-list", Arrays.asList("low-1", "low-2"),
-        "high-list", Arrays.asList("high-1", "high-2"),
-		"full-list", Arrays.asList("l1-1", "l1-2")
-		);
-```
-
-如果配置实例是临时的,需要显式地回收配置注入对象。 
-
-```Java
-priorityPropertyManager.unregisterConfigObject(config)
-```
 
-更多关于配置注入的用法,建议下载 java-chassis 的源码, 查看 TestConfigObjectFactory 类里面的示例。
\ No newline at end of file
+* 使用注解的场景
+
+        ```Java
+        ConfigWithAnnotation config = SCBEngine.getInstance().getPriorityPropertyManager()
+          .createConfigObject(ConfigWithAnnotation.class,
+                "key", "k",
+                "low-list", Arrays.asList("low-1", "low-2"),
+                "high-list", Arrays.asList("high-1", "high-2"),
+                "full-list", Arrays.asList("l1-1", "l1-2")
+                );
+        ```
+
+  ConfigWithAnnotation对象的longValue字段按以下顺序查找已配置的属性:
+
+    1.  root.low-1.a.high-1.b
+    2.  root.low-1.a.high-2.b
+    3.  root.low-2.a.high-1.b
+    4.  root.low-2.a.high-2.b
+
+  ConfigWithAnnotation对象的floatValue字段按以下顺序查找已配置的属性:
+  
+    1.  root.l1-1
+    2.  root.l1-2
+    
+* 不使用注解的场景
+
+        ```Java
+        ConfigNoAnnotation config = SCBEngine.getInstance()
+          .getPriorityPropertyManager().createConfigObject(ConfigNoAnnotation.class);
+        ```
+        
+    ConfigWithAnnotation 对象的 strValue 字段会查找已配置的属性 strValue,没有前缀和优先级。
+
+  
+***注意事项: *** 2.1.0 之前的版本, 如果系统中存在大量调用createConfigObject的情况, 需要调用
+
+    ```Java
+    priorityPropertyManager.unregisterConfigObject(config)
+    ```
+进行显示回收。 2.1.0 及其之后的版本, 不需要调用这个接口,系统创建的对象是 WeakReference, 再未被
+业务引用以后,会自动回收。 
+
+更多关于配置注入的用法,建议下载 java-chassis 的源码, 查看 TestConfigObjectFactory 类里面的示例。
diff --git a/java-chassis-reference/zh_CN/docs/general-development/file-download.md b/java-chassis-reference/zh_CN/docs/general-development/file-download.md
index 661b663..e9c2c19 100644
--- a/java-chassis-reference/zh_CN/docs/general-development/file-download.md
+++ b/java-chassis-reference/zh_CN/docs/general-development/file-download.md
@@ -72,6 +72,10 @@ public ResponseEntity<Resource> resource() {
 一样的, 使用 InputStream 需要 @ApiResponse 标识这是一个文件下载场景
 
 ```
+@GetMapping(path = "/inputStream")
+@ApiResponses({
+  @ApiResponse(code = 200, response = File.class, message = ""),
+})
 return ResponseEntity
     .ok()
     .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)