Skip to content

Commit dae4913

Browse files
authored
0.2.1 (#360)
* Fix #169 * Polish : #324 & #325 * Polish : #315 * Polish : #321 * Polish : #321 * Polish : #321 for test case * Polish : Update Demos * Polish : Update version to be 0.2.1 * Polish : #319 * Polish : #226 * Polish : #309 * Fix the test case's bugs * Fix the test case's bugs * Fix a JavaDoc issue * Update SNAPSHOT and add exclude list * Update SNAPSHOT to be 0.2.1-SNAPSHOT * Update JDK versions * Update JDK versions * Reactor & remove author info * Refactor : to save a shutdown hook thread * Remove javax.servlet:javax.servlet-api:3.1.0 that may cause class conflict, and use indirectly dependencies from spring-boot-starter-* * Polish #341 * Add the samples * Add a license * Add the samples of Zookeeper and Nacos * Update README.md * Fix the test cases
1 parent b5957e5 commit dae4913

File tree

25 files changed

+1205
-208
lines changed

25 files changed

+1205
-208
lines changed

README.md

+123-151
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,50 @@
2020

2121
You can introduce the latest `dubbo-spring-boot-starter` to your project by adding the following dependency to your pom.xml
2222
```xml
23-
<dependency>
24-
<groupId>com.alibaba.boot</groupId>
25-
<artifactId>dubbo-spring-boot-starter</artifactId>
26-
<version>0.2.1-SNAPSHOT</version>
27-
</dependency>
28-
29-
<!-- Dubbo -->
30-
<dependency>
31-
<groupId>com.alibaba</groupId>
32-
<artifactId>dubbo</artifactId>
33-
<version>2.6.5</version>
34-
</dependency>
35-
<!-- Spring Context Extras -->
36-
<dependency>
37-
<groupId>com.alibaba.spring</groupId>
38-
<artifactId>spring-context-support</artifactId>
39-
<version>1.0.2</version>
40-
</dependency>
23+
<properties>
24+
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
25+
<dubbo.version>2.6.5</dubbo.version>
26+
</properties>
27+
28+
<dependencyManagement>
29+
<dependencies>
30+
<!-- Spring Boot -->
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-dependencies</artifactId>
34+
<version>${spring-boot.version}</version>
35+
<type>pom</type>
36+
<scope>import</scope>
37+
</dependency>
38+
39+
<!-- Dubbo dependencies -->
40+
<dependency>
41+
<groupId>com.alibaba</groupId>
42+
<artifactId>dubbo-dependencies-bom</artifactId>
43+
<version>${dubbo.version}</version>
44+
<type>pom</type>
45+
<scope>import</scope>
46+
</dependency>
47+
</dependencies>
48+
</dependencyManagement>
49+
50+
<dependencies>
51+
<!-- Dubbo Spring Boot Starter -->
52+
<dependency>
53+
<groupId>com.alibaba.boot</groupId>
54+
<artifactId>dubbo-spring-boot-starter</artifactId>
55+
<version>0.2.1-SNAPSHOT</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.alibaba</groupId>
59+
<artifactId>dubbo</artifactId>
60+
<version>${dubbo.version}</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.netty</groupId>
64+
<artifactId>netty-all</artifactId>
65+
</dependency>
66+
</dependencies>
4167
```
4268

4369
If your project failed to resolve the dependency, try to add the following repository:
@@ -78,7 +104,7 @@ If you'd like to attempt to experience latest features, you also can build from
78104

79105
| versions | Java | Spring Boot | Dubbo |
80106
| -------- | ----- | ----------- | ---------- |
81-
| `0.2.0` | 1.8+ | `2.0.x` | `2.6.2` + |
107+
| `0.2.1` | 1.8+ | `2.1.x` | `2.6.2` + |
82108
| `0.1.1` | 1.7+ | `1.5.x` | `2.6.2` + |
83109

84110

@@ -103,148 +129,108 @@ public interface DemoService {
103129

104130
### Dubbo service(s) provider
105131

106-
Service Provider implements `DemoService`:
107-
108-
```java
109-
@Service(
110-
version = "1.0.0",
111-
application = "${dubbo.application.id}",
112-
protocol = "${dubbo.protocol.id}",
113-
registry = "${dubbo.registry.id}"
114-
)
115-
public class DefaultDemoService implements DemoService {
116-
117-
public String sayHello(String name) {
118-
return "Hello, " + name + " (from Spring Boot)";
119-
}
120-
121-
}
122-
```
123-
132+
1. Service Provider implements `DemoService`
124133

134+
```java
135+
@Service(version = "1.0.0")
136+
public class DefaultDemoService implements DemoService {
125137

126-
then, provides a bootstrap class:
127-
128-
```java
129-
@SpringBootApplication
130-
public class DubboProviderDemo {
131-
132-
public static void main(String[] args) {
133-
134-
SpringApplication.run(DubboProviderDemo.class,args);
138+
/**
139+
* The default value of ${dubbo.application.name} is ${spring.application.name}
140+
*/
141+
@Value("${dubbo.application.name}")
142+
private String serviceName;
135143

144+
public String sayHello(String name) {
145+
return String.format("[%s] : Hello, %s", serviceName, name);
146+
}
136147
}
148+
```
137149

138-
}
139-
```
140-
150+
2. Provides a bootstrap class
141151

152+
```java
153+
@EnableAutoConfiguration
154+
public class DubboProviderDemo {
142155

143-
last, configures `application.properties`:
144-
145-
```properties
146-
# Spring boot application
147-
spring.application.name = dubbo-provider-demo
148-
server.port = 9090
149-
management.port = 9091
150-
151-
# Base packages to scan Dubbo Components (e.g., @Service, @Reference)
152-
dubbo.scan.basePackages = com.alibaba.boot.dubbo.demo.provider.service
153-
154-
# Dubbo Config properties
155-
## ApplicationConfig Bean
156-
dubbo.application.id = dubbo-provider-demo
157-
dubbo.application.name = dubbo-provider-demo
158-
159-
## ProtocolConfig Bean
160-
dubbo.protocol.id = dubbo
161-
dubbo.protocol.name = dubbo
162-
dubbo.protocol.port = 12345
163-
164-
## RegistryConfig Bean
165-
dubbo.registry.id = my-registry
166-
dubbo.registry.address = N/A
167-
```
156+
public static void main(String[] args) {
157+
SpringApplication.run(DubboProviderDemo.class,args);
158+
}
159+
}
160+
```
168161

162+
3. Configures the `application.properties`:
169163

164+
```properties
165+
# Spring boot application
166+
spring.application.name=dubbo-auto-configuration-provider-demo
170167

171-
`DefaultDemoService`'s placeholders( `${dubbo.application.id}`, `${dubbo.protocol.id}`, `${dubbo.registry.id}` ) sources from `application.properties`.
168+
# Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service
169+
dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service
172170

171+
# Dubbo Application
172+
## The default value of dubbo.application.name is ${spring.application.name}
173+
## dubbo.application.name=${spring.application.name}
173174

175+
# Dubbo Protocol
176+
dubbo.protocol.name=dubbo
177+
dubbo.protocol.port=12345
174178

175-
More details, please refer to [Dubbo Provider Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider).
179+
## Dubbo Registry
180+
dubbo.registry.address=N/A
181+
```
176182

177183

178184

179185
### Dubbo service(s) consumer
180186

187+
1. Service consumer also provides a bootstrap class to reference `DemoService`
181188

189+
```java
190+
@EnableAutoConfiguration
191+
public class DubboConsumerBootstrap {
182192

183-
Service consumer requires Spring Beans to reference `DemoService`:
184-
185-
```java
186-
@RestController
187-
public class DemoConsumerController {
188-
189-
@Reference(version = "1.0.0",
190-
application = "${dubbo.application.id}",
191-
url = "dubbo://localhost:12345")
192-
private DemoService demoService;
193-
194-
@RequestMapping("/sayHello")
195-
public String sayHello(@RequestParam String name) {
196-
return demoService.sayHello(name);
197-
}
198-
199-
}
200-
```
201-
202-
203-
204-
then, also provide a bootstrap class:
205-
206-
```java
207-
@SpringBootApplication(scanBasePackages = "com.alibaba.boot.dubbo.demo.consumer.controller")
208-
public class DubboConsumerDemo {
193+
private final Logger logger = LoggerFactory.getLogger(getClass());
209194

210-
public static void main(String[] args) {
195+
@Reference(version = "1.0.0", url = "dubbo://localhost:12345")
196+
private DemoService demoService;
211197

212-
SpringApplication.run(DubboConsumerDemo.class,args);
198+
@Bean
199+
public ApplicationRunner runner() {
200+
return args -> {
201+
logger.info(demoService.sayHello("mercyblitz"));
202+
};
203+
}
213204

205+
public static void main(String[] args) {
206+
SpringApplication.run(DubboConsumerBootstrap.class).close();
207+
}
214208
}
209+
```
215210

216-
}
217-
```
218-
219-
211+
2. configures `application.properties`
220212

221-
last, configures `application.properties`:
213+
```properties
214+
# Spring boot application
215+
spring.application.name = dubbo-consumer-demo
216+
server.port = 8080
217+
management.port = 8081
222218

223-
```properties
224-
# Spring boot application
225-
spring.application.name = dubbo-consumer-demo
226-
server.port = 8080
227-
management.port = 8081
228219

220+
# Dubbo Config properties
221+
## ApplicationConfig Bean
222+
dubbo.application.id = dubbo-consumer-demo
223+
dubbo.application.name = dubbo-consumer-demo
229224

230-
# Dubbo Config properties
231-
## ApplicationConfig Bean
232-
dubbo.application.id = dubbo-consumer-demo
233-
dubbo.application.name = dubbo-consumer-demo
234-
235-
## ProtocolConfig Bean
236-
dubbo.protocol.id = dubbo
237-
dubbo.protocol.name = dubbo
238-
dubbo.protocol.port = 12345
239-
```
240-
225+
## ProtocolConfig Bean
226+
dubbo.protocol.id = dubbo
227+
dubbo.protocol.name = dubbo
228+
dubbo.protocol.port = 12345
229+
```
241230

231+
If `DubboProviderDemo` works well, please mark sure `DubboProviderDemo` is started.
242232

243-
If `DubboProviderDemo` works well, please mark sure Dubbo service(s) is active.
244-
245-
246-
247-
More details, please refer to [Dubbo Consumer Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer)
233+
More details, please refer to [Samples](dubbo-spring-boot-samples).
248234

249235

250236

@@ -261,7 +247,7 @@ Having trouble with Dubbo Spring Boot? We’d like to help!
261247

262248
## Building from Source
263249

264-
If you want to try out thr latest features of Dubbo Spring Boot, it can be easily built with the [maven wrapper](https://github.com/takari/maven-wrapper). Your JDK is 1.7 or above.
250+
If you want to try out thr latest features of Dubbo Spring Boot, it can be easily built with the [maven wrapper](https://github.com/takari/maven-wrapper). Your JDK is 1.8 or above.
265251

266252
```
267253
$ ./mvnw clean install
@@ -301,24 +287,10 @@ The main usage of `dubbo-spring-boot-parent` is providing dependencies managemen
301287
302288
### [dubbo-spring-boot-samples](dubbo-spring-boot-samples)
303289
304-
The samples project of Dubbo Spring Boot that includes two parts:
305-
306-
307-
308-
#### [Dubbo Provider Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider)
309-
310-
Dubbo Service will be exported on localhost with port `12345`.
311-
312-
* [Health Checks](dubbo-spring-boot-actuator#health-checks): http://localhost:9091/health
313-
* [Dubbo Endpoint](dubbo-spring-boot-actuator#endpoints): http://localhost:9091/dubbo
314-
315-
316-
317-
#### [Dubbo Consumer Sample](dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer)
318-
319-
Dubbo Service will be consumed at Spring WebMVC `Controller`.
320-
321-
* Demo `Controller`: http://localhost:8080/sayHello?name=HelloWorld
322-
* [Health Checks](dubbo-spring-boot-actuator#health-checks): http://localhost:8081/actuator/health
323-
* [Dubbo Endpoint](dubbo-spring-boot-actuator#endpoints): http://localhost:8081/actuator/dubbo
290+
The samples project of Dubbo Spring Boot that includes:
324291
292+
- [Auto-Configuaration Samples](dubbo-spring-boot-samples/auto-configure-samples)
293+
- [Externalized Configuration Samples](dubbo-spring-boot-samples/externalized-configuration-samples)
294+
- [Registry Zookeeper Samples](dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples)
295+
- [Registry Nacos Samples](dubbo-spring-boot-samples/dubbo-registry-nacos-samples)
296+
- [Sample API](dubbo-spring-boot-samples/sample-api)

dubbo-spring-boot-autoconfigure/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<groupId>com.alibaba.boot</groupId>
2222
<artifactId>dubbo-spring-boot-parent</artifactId>
2323
<version>0.2.1-SNAPSHOT</version>
24-
<relativePath>../dubbo-spring-boot-parent</relativePath>
24+
<relativePath>../dubbo-spring-boot-parent/pom.xml</relativePath>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java

+20
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme
6464
*/
6565
private static final String DUBBO_APPLICATION_NAME_PROPERTY = "dubbo.application.name";
6666

67+
/**
68+
* The property name of {@link EnableDubboConfig#multiple() @EnableDubboConfig.multiple()}
69+
*/
70+
private static final String DUBBO_CONFIG_MULTIPLE_PROPERTY = "dubbo.config.multiple";
71+
72+
/**
73+
* The property name of {@link ApplicationConfig#getQosEnable() application's QOS enable}
74+
*/
75+
private static final String DUBBO_APPLICATION_QOS_ENABLE_PROPERTY = "dubbo.application.qos-enable";
76+
6777
@Override
6878
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
6979
MutablePropertySources propertySources = environment.getPropertySources();
@@ -81,6 +91,8 @@ public int getOrder() {
8191
private Map<String, Object> createDefaultProperties(ConfigurableEnvironment environment) {
8292
Map<String, Object> defaultProperties = new HashMap<String, Object>();
8393
setDubboApplicationNameProperty(environment, defaultProperties);
94+
setDubboConfigMultipleProperty(defaultProperties);
95+
setDubboApplicationQosEnableProperty(defaultProperties);
8496
return defaultProperties;
8597
}
8698

@@ -92,6 +104,14 @@ private void setDubboApplicationNameProperty(Environment environment, Map<String
92104
}
93105
}
94106

107+
private void setDubboConfigMultipleProperty(Map<String, Object> defaultProperties) {
108+
defaultProperties.put(DUBBO_CONFIG_MULTIPLE_PROPERTY, Boolean.TRUE.toString());
109+
}
110+
111+
private void setDubboApplicationQosEnableProperty(Map<String, Object> defaultProperties) {
112+
defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY, Boolean.FALSE.toString());
113+
}
114+
95115
/**
96116
* Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)
97117
*

0 commit comments

Comments
 (0)