You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/07/19 12:25:04 UTC

[dubbo-website] branch master updated: [fix] Annotation 配置优化 (#1242)

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

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a79fca46b [fix] Annotation 配置优化 (#1242)
9a79fca46b is described below

commit 9a79fca46b04bca3b59c12fb720c09d181cdf1b5
Author: JIAN ZHONG <11...@qq.com>
AuthorDate: Tue Jul 19 20:24:59 2022 +0800

    [fix] Annotation 配置优化 (#1242)
---
 .../reference-manual/config/annotation/_index.md   | 24 +++++++++++++---------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/content/zh/docs3-building/java-sdk/reference-manual/config/annotation/_index.md b/content/zh/docs3-building/java-sdk/reference-manual/config/annotation/_index.md
index 727188284f..57c955a64a 100644
--- a/content/zh/docs3-building/java-sdk/reference-manual/config/annotation/_index.md
+++ b/content/zh/docs3-building/java-sdk/reference-manual/config/annotation/_index.md
@@ -6,20 +6,17 @@ weight: 3
 description: "以 Annotation、Spring Boot 开发 Dubbo 应用"
 ---
 
-{{% alert title="提示" color="primary" %}}
 本文以 Spring Boot + Annotation 模式描述 Dubbo 应用开发,在此查看无 Spring Boot 的 Spring 注解开发模式 [完整示例](https://github.com/apache/dubbo-samples/tree/master/dubbo-samples-annotation)
-{{% /alert %}}
 
 在 Dubbo Spring Boot 开发中,你只需要增加几个注解,并配置 `application.properties` 或 `application.yml` 文件即可完成 Dubbo 服务定义:
 * 注解有 `@DubboService`、`@DubboReference` 与 `EnableDubbo`。其中 `@DubboService` 与 `@DubboReference` 用于标记 Dubbo 服务,`EnableDubbo` 启动 Dubbo 相关配置并指定 Spring Boot 扫描包路径。
 * 配置文件 `application.properties` 或 `application.yml`
 
-## 使用讲解
 以下内容的完整示例请参考 [dubbo-samples](https://github.com/apache/dubbo-samples/tree/master/dubbo-samples-spring-boot)
 
 ### 增加 Maven 依赖
 
-使用 Dubbo Spring Boot Starter 首先引入以下下 Maven 依赖
+使用 Dubbo Spring Boot Starter 首先引入以下 Maven 依赖
 ```xml
     <dependencyManagement>
         <dependencies>
@@ -83,7 +80,8 @@ description: "以 Annotation、Spring Boot 开发 Dubbo 应用"
     </dependencies>
 ```
 
-> 注意区分上面的 <dependenciesManagement/> 与 <dependencies/>
+#### 注意:
+区分上面的 **与**
 
 ### application.yml 或 application.properties
 
@@ -125,8 +123,13 @@ public class ProviderConfiguration {
     }
 }
 ```
+## 注解
+- @DubboService 注解
+- @DubboReference 注解
+- @EnableDubbo 注解
+- 扩展注解
 
-### @DubboService 注解
+#### @DubboService 注解
 
 > `@Service` 注解从 3.0 版本开始就已经废弃,改用 `@DubboService`,以区别于 Spring 的 `@Service` 注解
 
@@ -143,7 +146,7 @@ public class DemoServiceImpl implements DemoService {}
 public class DemoServiceImpl implements DemoService {}
 ```
 
-### @DubboReference 注解
+#### @DubboReference 注解
 
 > `@Reference` 注解从 3.0 版本开始就已经废弃,改用 `@DubboReference`,以区别于 Spring 的 `@Reference` 注解
 
@@ -157,7 +160,7 @@ public class DemoClient {
 
 `@DubboReference` 注解将自动注入为 Dubbo 服务代理实例,使用 demoService 即可发起远程服务调用
 
-### @EnableDubbo 注解
+#### @EnableDubbo 注解
 `@EnableDubbo` 注解必须配置,否则将无法加载 Dubbo 注解定义的服务,`@EnableDubbo` 可以定义在主类上
 
 ```java
@@ -172,7 +175,7 @@ public class ProviderApplication {
 
 Spring Boot 注解默认只会扫描 main 类所在的 package,如果服务定义在其它 package 中,需要增加配置 `EnableDubbo(scanBasePackages = {"org.apache.dubbo.springboot.demo.provider"})`
 
-### 扩展注解的配置
+#### 扩展注解配置
 虽然可以通过 `@DubboService` 和 `DubboReference` 调整配置参数(如下代码片段所示),但总体来说注解提供的配置项还是非常有限。在这种情况下,如果有更复杂的参数设置需求,可以使用 `Java Config` 或 `dubbo.properties` 两种方式。
 
 ```java
@@ -209,6 +212,7 @@ dubbo.service.org.apache.dubbo.springboot.demo.DemoService.timeout=5000
 dubbo.service.org.apache.dubbo.springboot.demo.DemoService.parameters=[{myKey:myValue},{anotherKey:anotherValue}]
 dubbo.reference.org.apache.dubbo.springboot.demo.DemoService.timeout=6000
 ```
-> properties 格式配置目前结构性不太强,比如体现在 key 字段冗余较多,后续会考虑提供对于 yaml 格式的支持。
+#### 提示:
+properties 格式配置目前结构性不太强,比如体现在 key 字段冗余较多,后续会考虑提供对于 yaml 格式的支持。