You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by hy...@apache.org on 2019/07/19 05:29:57 UTC
[dubbo-website] branch master updated: Fix annotation configuration
inconsistent in annotation doc (#430)
This is an automated email from the ASF dual-hosted git repository.
hyunkun 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 91fa44c Fix annotation configuration inconsistent in annotation doc (#430)
91fa44c is described below
commit 91fa44c1b1a9aeb192c946cdf2562b6cf9ecadbd
Author: 天璇 <ca...@126.com>
AuthorDate: Fri Jul 19 13:29:53 2019 +0800
Fix annotation configuration inconsistent in annotation doc (#430)
---
docs/en-us/user/configuration/annotation.md | 132 ++++++++++++----------------
docs/zh-cn/user/configuration/annotation.md | 11 ++-
2 files changed, 62 insertions(+), 81 deletions(-)
diff --git a/docs/en-us/user/configuration/annotation.md b/docs/en-us/user/configuration/annotation.md
index 0d82b1b..20afa09 100644
--- a/docs/en-us/user/configuration/annotation.md
+++ b/docs/en-us/user/configuration/annotation.md
@@ -1,116 +1,94 @@
+---
+title: Annotation Configuration
+keywords: dubbo,annotation configuration
+description: Annotation Configuration
+---
+
# Annotation Configuration
- Requires`2.5.7` or higher
+ Requires`2.6.3` or higher
+ click here to view the [complete sample](https://github.com/apache/dubbo-samples/tree/master/dubbo-samples-annotation)
## Provider Side
### `Service` annotation for exporting
```java
-import org.apache.dubbo.config.annotation.Service;
-
-@Service(timeout = 5000)
-public class AnnotateServiceImpl implements AnnotateService {
- // ...
+@Service
+public class AnnotationServiceImpl implements AnnotationService {
+ @Override
+ public String sayHello(String name) {
+ return "annotation: hello, " + name;
+ }
}
```
-### Use JavaConfig for common parts
-
-```java
-@Configuration
-public class DubboConfiguration {
-
- @Bean
- public ApplicationConfig applicationConfig() {
- ApplicationConfig applicationConfig = new ApplicationConfig();
- applicationConfig.setName("provider-test");
- return applicationConfig;
- }
-
- @Bean
- public RegistryConfig registryConfig() {
- RegistryConfig registryConfig = new RegistryConfig();
- registryConfig.setAddress("zookeeper://127.0.0.1:2181");
- registryConfig.setClient("curator");
- return registryConfig;
- }
-}
+### Add application sharing configuration
+
+```properties
+# dubbo-provider.properties
+dubbo.application.name=annotation-provider
+dubbo.registry.address=zookeeper://127.0.0.1:2181
+dubbo.protocol.name=dubbo
+dubbo.protocol.port=20880
```
-### Path to scan
+### Spring scan path
```java
-@SpringBootApplication
-@DubboComponentScan(basePackages = "org.apache.dubbo.test.service.impl")
-public class ProviderTestApp {
- // ...
+@Configuration
+@EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.simple.annotation.impl")
+@PropertySource("classpath:/spring/dubbo-provider.properties")
+static public class ProviderConfiguration {
+
}
```
-
## Consumer Side
### `Reference` annotation for reference
```java
-public class AnnotationConsumeService {
+@Component("annotationAction")
+public class AnnotationAction {
- @org.apache.dubbo.config.annotation.Reference
- public AnnotateService annotateService;
+ @Reference
+ private AnnotationService annotationService;
- // ...
+ public String doSayHello(String name) {
+ return annotationService.sayHello(name);
+ }
}
-
```
-
-### Use JavaConfig for common parts
+### Add application sharing configuration
```java
-@Configuration
-public class DubboConfiguration {
-
- @Bean
- public ApplicationConfig applicationConfig() {
- ApplicationConfig applicationConfig = new ApplicationConfig();
- applicationConfig.setName("consumer-test");
- return applicationConfig;
- }
-
- @Bean
- public ConsumerConfig consumerConfig() {
- ConsumerConfig consumerConfig = new ConsumerConfig();
- consumerConfig.setTimeout(3000);
- return consumerConfig;
- }
-
- @Bean
- public RegistryConfig registryConfig() {
- RegistryConfig registryConfig = new RegistryConfig();
- registryConfig.setAddress("zookeeper://127.0.0.1:2181");
- registryConfig.setClient("curator");
- return registryConfig;
- }
-}
+# dubbo-consumer.properties
+dubbo.application.name=annotation-consumer
+dubbo.registry.address=zookeeper://127.0.0.1:2181
+dubbo.consumer.timeout=3000
```
-### Path to scan
+### Spring scan path
```java
-@SpringBootApplication
-@DubboComponentScan(basePackages = "org.apache.dubbo.test.service")
-public class ConsumerTestApp {
- // ...
+@Configuration
+@EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.simple.annotation.action")
+@PropertySource("classpath:/spring/dubbo-consumer.properties")
+@ComponentScan(value = {"org.apache.dubbo.samples.simple.annotation.action"})
+static public class ConsumerConfiguration {
+
}
```
-## NOTES
+### Invoke service
-All annotations in 2.5.7 will be removed later, if you have used these annotations in your project, please upgrade to the latest version.
-
-```xml
-<dubbo:annotation package="org.apache.dubbo.test.service" />
+```java
+public static void main(String[] args) throws Exception {
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
+ context.start();
+ final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
+ String hello = annotationAction.doSayHello("world");
+}
```
-
-
diff --git a/docs/zh-cn/user/configuration/annotation.md b/docs/zh-cn/user/configuration/annotation.md
index e26bd85..cbfb72a 100644
--- a/docs/zh-cn/user/configuration/annotation.md
+++ b/docs/zh-cn/user/configuration/annotation.md
@@ -1,3 +1,9 @@
+---
+title: 注解配置
+keywords: dubbo,注解配置
+description: 注解配置
+---
+
# 注解配置
需要 `2.6.3` 及以上版本支持
@@ -38,7 +44,6 @@ static public class ProviderConfiguration {
}
```
-
## 服务消费方
### `Reference`注解引用服务
@@ -56,7 +61,6 @@ public class AnnotationAction {
}
```
-
### 增加应用共享配置
@@ -79,7 +83,7 @@ static public class ConsumerConfiguration {
}
```
-### 调动服务
+### 调用服务
```java
public static void main(String[] args) throws Exception {
@@ -89,4 +93,3 @@ public static void main(String[] args) throws Exception {
String hello = annotationAction.doSayHello("world");
}
```
-