Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dubbo升级到2.6.1, spring boot 升级到2.0.1 #345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 34 additions & 57 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,52 +1,46 @@
# spring-boot-starter-dubbo


spring-boot-start-dubbo,让你可以使用spring-boot的方式开发dubbo程序。使dubbo开发变得如此简单。

让你可以使用`spring-boot`的方式开发`dubbo`程序。使`dubbo`开发变得如此简单。
#spring-boot-start-dubbo

## 如何使用

### 1. `clone`代码(可选,已经发布到中央仓库,可以直接依赖[中央仓库的稳定版本](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22io.dubbo.springboot%22%20AND%20a%3A%22spring-boot-starter-dubbo%22)
### 1. clone 代码(可选,已经发布到中央仓库,可以直接依赖中央仓库的稳定版本

```sh
```
git clone git@github.com:teaey/spring-boot-starter-dubbo.git
```

### 2. 编译安装(可选)

```sh
```
cd spring-boot-starter-dubbo
mvn clean install
```

### 3. 修改`maven`配置文件(可以参考样例[`spring-boot-starter-dubbo-sample`](https://github.com/teaey/spring-boot-starter-dubbo-sample))

* 在`spring boot`项目的`pom.xml`增加`parent`:
### 3. 修改maven配置文件(可以参考样例[spring-boot-starter-dubbo-sample](https://github.com/teaey/spring-boot-starter-dubbo-sample))

```xml
* 在Spring Boot项目的pom.xml增加parent:
```
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
```

* 在`spring boot`项目的`pom.xml`中添加以下依赖:
* 在Spring Boot项目的pom.xml中添加以下依赖:

根据实际情况依赖最新版本

```xml
```
<dependency>
<groupId>io.dubbo.springboot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.0.0</version>
<groupId>io.dubbo.springboot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.0.0</version>
</dependency>
```

* `maven`插件用于打包成可执行的`uber-jar`文件,添加以下插件(这里一定要加载需要打包成`jar`的`mudule`的`pom`中)

```xml
* maven插件用于打包成可执行的uber-jar文件,添加以下插件(这里一定要加载需要打包成jar的mudule的pom中)
```
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -56,9 +50,9 @@ mvn clean install

### 4. 发布服务

服务接口
服务接口:

```java
```
package cn.teaey.sprintboot.test;

public interface EchoService {
Expand All @@ -68,9 +62,8 @@ public interface EchoService {
```


在`application.properties`添加`Dubbo`的版本信息和客户端超时信息,如下:

```properties
在application.properties添加Dubbo的版本信息和客户端超时信息,如下:
```
spring.dubbo.application.name=provider
spring.dubbo.registry.address=zookeeper://192.168.99.100:32770
spring.dubbo.protocol.name=dubbo
Expand All @@ -79,11 +72,9 @@ spring.dubbo.scan=cn.teaey.sprintboot.test
```


在`Spring Application`的`application.properties`中添加`spring.dubbo.scan`即可支持`Dubbo`服务发布,其中`scan`表示要扫描的`package`目录。

* `spring boot`启动

```java
在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录
* spring boot启动
```
package cn.teaey.sprintboot.test;

import org.springframework.boot.SpringApplication;
Expand All @@ -97,10 +88,8 @@ public class Server {
}

```

* 编写你的`Dubbo`服务,只需要添加要发布的服务实现上添加`@Service`,如下:

```java
* 编写你的Dubbo服务,只需要添加要发布的服务实现上添加 @Service ,如下
```
package cn.teaey.sprintboot.test;

import com.alibaba.dubbo.config.annotation.Service;
Expand All @@ -116,21 +105,17 @@ public class EchoServerImpl implements EchoService {

```

### 5. 消费`Dubbo`服务

* 在`application.properties`添加`Dubbo`的版本信息和客户端超时信息,如下:

```properties
### 5. 消费Dubbo服务
* 在application.properties添加Dubbo的版本信息和客户端超时信息,如下:
```
spring.dubbo.application.name=consumer
spring.dubbo.registry.address=zookeeper://192.168.99.100:32770
spring.dubbo.scan=cn.teaey.sprintboot.test
```
在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录

在`Spring Application`的`application.properties`中添加`spring.dubbo.scan`即可支持`Dubbo`服务发布,其中`scan`表示要扫描的`package`目录。

* `spring boot`启动

```java
* spring boot启动
```
package cn.teaey.sprintboot.test;

import org.springframework.boot.SpringApplication;
Expand All @@ -147,10 +132,8 @@ public class Client {
}

```

* 引用`Dubbo`服务,只需要添加要发布的服务实现上添加`@Reference`,如下:

```java
* 引用Dubbo服务,只需要添加要发布的服务实现上添加 @Reference ,如下:
```
package cn.teaey.sprintboot.test;

import com.alibaba.dubbo.config.annotation.Reference;
Expand All @@ -163,14 +146,8 @@ public class AbcService {
}
```

### 6. `monitor`监控中心
* 在`application.properties`添加`monitor`监控中心配置(服务端和消费端相同),如下:

```properties
spring.dubbo.monitor.protocol=registry
```
### 6. 打包

### 7. 打包
> 可以直接执行Server或者Client启动

- 可以直接执行`Server`或者`Client`启动
- 可以通过`mvn clean package`打包成可执行的`uber-jar`文件
> 可以通过mvn clean package 打包成可执行的uber-jar文件
20 changes: 7 additions & 13 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<version>2.0.1.RELEASE</version>
</parent>

<groupId>io.dubbo.springboot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<packaging>jar</packaging>
<url>https://github.com/teaey/spring-boot-starter-dubbo</url>
<name>spring-boot-starter-dubbo</name>

<properties>
<java.version>1.8</java.version>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<spring-boot.version>1.5.3.RELEASE</spring-boot.version>
<dubbo.version>2.5.4-SNAPSHOT</dubbo.version>
<zkclient.version>0.10</zkclient.version>

<spring-boot.version>2.0.1.RELEASE</spring-boot.version>
<dubbo.version>2.6.1</dubbo.version>
<version.compiler-plugin>3.5.1</version.compiler-plugin>
<version.source-plugin>2.2.1</version.source-plugin>
<version.javadoc-plugin>2.9.1</version.javadoc-plugin>
<version.maven-gpg-plugin>1.5</version.maven-gpg-plugin>

</properties>

<developers>
Expand Down Expand Up @@ -58,7 +57,7 @@
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>${zkclient.version}</version>
<version>0.7</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
Expand All @@ -74,11 +73,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
89 changes: 14 additions & 75 deletions src/main/java/io/dubbo/springboot/DubboAutoConfiguration.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package io.dubbo.springboot;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.MethodConfig;
import com.alibaba.dubbo.config.ModuleConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -17,79 +12,23 @@
@EnableConfigurationProperties(DubboProperties.class)
public class DubboAutoConfiguration {

@Autowired
private DubboProperties dubboProperties;
@Autowired
private DubboProperties dubboProperties;

@Bean
public ApplicationConfig requestApplicationConfig() {
ApplicationConfig applicationConfig = dubboProperties.getApplication();
if (applicationConfig == null) {
applicationConfig = new ApplicationConfig();
}
return applicationConfig;
}
@Bean
public ApplicationConfig requestApplicationConfig() {
return dubboProperties.getApplication();
}

@Bean
public RegistryConfig requestRegistryConfig() {
RegistryConfig registryConfig = dubboProperties.getRegistry();
if (registryConfig == null) {
registryConfig = new RegistryConfig();
}
return registryConfig;
}
@Bean
public RegistryConfig requestRegistryConfig() {
return dubboProperties.getRegistry();
}

@Bean
public ProtocolConfig requestProtocolConfig() {
ProtocolConfig protocolConfig = dubboProperties.getProtocol();
if (protocolConfig == null) {
protocolConfig = new ProtocolConfig();
}
return protocolConfig;
}
@Bean
public ProtocolConfig requestProtocolConfig() {
return dubboProperties.getProtocol();
}

@Bean
public MonitorConfig requestMonitorConfig() {
MonitorConfig monitorConfig = dubboProperties.getMonitor();
if (monitorConfig == null) {
monitorConfig = new MonitorConfig();
}
return monitorConfig;
}

@Bean
public ProviderConfig requestProviderConfig() {
ProviderConfig providerConfig = dubboProperties.getProvider();
if (providerConfig == null) {
providerConfig = new ProviderConfig();
}
return providerConfig;
}

@Bean
public ModuleConfig requestModuleConfig() {
ModuleConfig moduleConfig = dubboProperties.getModule();
if (moduleConfig == null) {
moduleConfig = new ModuleConfig();
}
return moduleConfig;
}

@Bean
public MethodConfig requestMethodConfig() {
MethodConfig methodConfig = dubboProperties.getMethod();
if (methodConfig == null) {
methodConfig = new MethodConfig();
}
return methodConfig;
}

@Bean
public ConsumerConfig requestConsumerConfig() {
ConsumerConfig consumerConfig = dubboProperties.getConsumer();
if (consumerConfig == null) {
consumerConfig = new ConsumerConfig();
}
return consumerConfig;
}

}
Empty file.
17 changes: 1 addition & 16 deletions src/main/java/io/dubbo/springboot/DubboHolderListener.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.dubbo.springboot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
Expand All @@ -11,10 +9,7 @@
* @author xiaofei.wxf(teaey)
* @since 0.0.0
*/
@SuppressWarnings("rawtypes")
public class DubboHolderListener implements ApplicationListener {
private static final Logger LOGGER = LoggerFactory.getLogger(DubboHolderListener.class);

private static Thread holdThread;
private static Boolean running = Boolean.FALSE;

Expand All @@ -27,9 +22,7 @@ public void onApplicationEvent(ApplicationEvent event) {
holdThread = new Thread(new Runnable() {
@Override
public void run() {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(Thread.currentThread().getName());
}
System.out.println(Thread.currentThread().getName());
while (running && !Thread.currentThread().isInterrupted()) {
try {
Thread.sleep(2000);
Expand All @@ -50,12 +43,4 @@ public void run() {
}
}
}

public static void stopApplicationContext(Boolean stop){
running = stop.booleanValue();
if (null != holdThread) {
holdThread.interrupt();
holdThread = null;
}
}
}
Loading