Skip to content

Commit

Permalink
start 2.0.0:支持更多配置
Browse files Browse the repository at this point in the history
  • Loading branch information
xionghui committed Mar 11, 2018
1 parent cea3855 commit ab0ad88
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 317 deletions.
35 changes: 11 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,15 @@ Support jdk version 1.6 or 1.6+
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>1.0.2</version>
<version>2.0.0</version>
</dependency>
```
* single protocol config, add dubbo configuration in application.properties, demo:

```properties
spring.dubbo.appname=dubbo-spring-boot-starter-provider-test
spring.dubbo.registry=multicast://224.0.0.0:1111
spring.dubbo.protocol=dubbo
```
* multi protocol config(version >= 1.0.2), add dubbo configuration in application.properties, demo:
* add dubbo configuration in application.properties, demo:

```properties
spring.dubbo.appname=dubbo-spring-boot-starter-provider-test
spring.dubbo.registry=multicast://224.0.0.0:1111
# dubbo protocol
spring.dubbo.protocols.dubbo.name=dubbo
spring.dubbo.protocols.dubbo.port=20801
# hessian protocol
spring.dubbo.protocols.hessian.name=hessian
spring.dubbo.protocols.hessian.port=20802
spring.application.name=dubbo-spring-boot-starter
spring.dubbo.server=true
spring.dubbo.registry=N/A
```

* then add `@EnableDubboConfiguration` on Spring Boot Application, indicates that dubbo is enabled.(web or non-web application can use dubbo provider)
Expand Down Expand Up @@ -71,16 +59,14 @@ public class HelloServiceImpl implements IHelloService {
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>1.0.2</version>
<version>2.0.0</version>
</dependency>
```

* add dubbo configuration in application.properties, demo:

```properties
spring.dubbo.appname=dubbo-spring-boot-starter-consumer-test
spring.dubbo.registry=multicast://224.0.0.0:1111
spring.dubbo.protocol=dubbo
spring.application.name=dubbo-spring-boot-starter
```

* then add `@EnableDubboConfiguration` on Spring Boot Application
Expand All @@ -98,13 +84,14 @@ public class DubboConsumerLauncher {
```java
@Component
public class HelloConsumer {
@Reference
@Reference(url = "dubbo://127.0.0.1:20880")
private IHelloService iHelloService;

}
```

### Reference

* dubbo: http://dubbo.io/
* spring-boot: http://projects.spring.io/spring-boot/
* dubbo: http://dubbo.io
* spring-boot: http://projects.spring.io/spring-boot
* dubbo-spring-boot-project: https://github.com/dubbo/dubbo-spring-boot-project
36 changes: 11 additions & 25 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,16 @@ Dubbo Spring Boot Starter。也可以关注dubbo官方的[dubbo-spring-boot-proj
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>1.0.2</version>
<version>2.0.0</version>
</dependency>
```

* 单协议配置,在application.properties添加dubbo的相关配置信息,样例配置如下:

```properties
spring.dubbo.appname=dubbo-spring-boot-starter-provider-test
spring.dubbo.registry=multicast://224.0.0.0:1111
spring.dubbo.protocol=dubbo
```

* 多协议配置(version>=1.0.2),application.properties添加dubbo的相关配置信息,样例配置如下:
* 在application.properties添加dubbo的相关配置信息,样例配置如下:

```properties
spring.dubbo.appname=dubbo-spring-boot-starter-provider-test
spring.dubbo.registry=multicast://224.0.0.0:1111
# dubbo协议
spring.dubbo.protocols.dubbo.name=dubbo
spring.dubbo.protocols.dubbo.port=20801
# hessian协议
spring.dubbo.protocols.hessian.name=hessian
spring.dubbo.protocols.hessian.port=20802
spring.application.name=dubbo-spring-boot-starter
spring.dubbo.server=true
spring.dubbo.registry=N/A
```

注:这个配置只针对服务提供端,消费端不用指定协议,它自己会根据服务端的地址信息和@Reference注解去解析协议
Expand Down Expand Up @@ -75,16 +62,14 @@ public class HelloServiceImpl implements IHelloService {
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>1.0.2</version>
<version>2.0.0</version>
</dependency>
```

* 在application.properties添加dubbo的相关配置信息,样例配置如下:

```properties
spring.dubbo.appname=dubbo-spring-boot-starter-consumer-test
spring.dubbo.registry=multicast://224.0.0.0:1111
spring.dubbo.protocol=dubbo
spring.application.name=dubbo-spring-boot-starter
```

* 开启`@EnableDubboConfiguration`
Expand All @@ -102,13 +87,14 @@ public class DubboConsumerLauncher {
```java
@Component
public class HelloConsumer {
@Reference
@Reference(url = "dubbo://127.0.0.1:20880")
private IHelloService iHelloService;

}
```

### 参考文档

* dubbo 介绍: http://dubbo.io/
* spring-boot 介绍: http://projects.spring.io/spring-boot/
* dubbo: http://dubbo.io
* spring-boot: http://projects.spring.io/spring-boot
* dubbo-spring-boot-project: https://github.com/dubbo/dubbo-spring-boot-project
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>dubbo-spring-boot-starter</name>
Expand Down Expand Up @@ -35,11 +35,6 @@
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,29 @@

import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.spring.boot.health.DubboHealthIndicator;
import com.alibaba.dubbo.spring.boot.server.DubboServer;

/**
* Dubbo common configuration
* Dubbo configuration
*
* @author xionghui
* @version 1.0.0
* @version 2.0.0
* @since 1.0.0
*/
@Configuration
@EnableConfigurationProperties(DubboProperties.class)
public class DubboAutoConfiguration {
@Autowired
private DubboProperties properties;

@Bean
@ConditionalOnMissingBean
public ApplicationConfig dubboApplicationConfig(Environment environment) {
String appname = this.properties.getAppname();
if (appname == null) {
appname = environment.getProperty("spring.application.name");
}
ApplicationConfig appConfig = new ApplicationConfig();
appConfig.setName(appname);
return appConfig;
}

/**
* Start a non-daemon thread
*
* @since 1.0.2
* @return DubboServer
*/
@Bean
Expand Down Expand Up @@ -73,24 +53,6 @@ public void run() {
return dubboServer;
}

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.dubbo", name = "registry")
public RegistryConfig dubboRegistryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress(this.properties.getRegistry());
return registryConfig;
}

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.dubbo", name = "monitor")
public MonitorConfig dubboMonitorConfig() {
MonitorConfig monitorConfig = new MonitorConfig();
monitorConfig.setAddress(this.properties.getMonitor());
return monitorConfig;
}

@Bean
public DubboHealthIndicator dubboHealthIndicator() {
return new DubboHealthIndicator();
Expand Down
Loading

0 comments on commit ab0ad88

Please sign in to comment.