Skip to content

Commit e363883

Browse files
committed
springboot_dubbo
1 parent c244391 commit e363883

13 files changed

Lines changed: 346 additions & 0 deletions

File tree

springboot_dubbo/pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>springboot_chowder</artifactId>
7+
<groupId>com.oven</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>springboot_dubbo</artifactId>
13+
<packaging>pom</packaging>
14+
<modules>
15+
<module>springboot_dubbo_client</module>
16+
<module>springboot_dubbo_server</module>
17+
<module>springboot_dubbo_common_api</module>
18+
</modules>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-web</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.apache.dubbo</groupId>
28+
<artifactId>dubbo-spring-boot-starter</artifactId>
29+
<version>2.7.3</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.apache.curator</groupId>
34+
<artifactId>curator-framework</artifactId>
35+
<version>4.0.1</version>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.apache.curator</groupId>
40+
<artifactId>curator-recipes</artifactId>
41+
<version>4.0.1</version>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>log4j</groupId>
46+
<artifactId>log4j</artifactId>
47+
<version>1.2.17</version>
48+
</dependency>
49+
</dependencies>
50+
51+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>springboot_dubbo</artifactId>
7+
<groupId>com.oven</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>springboot_dubbo_client</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.oven</groupId>
17+
<artifactId>springboot_dubbo_common_api</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
</dependencies>
21+
22+
</project>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# springboot炖dubbo-client
2+
### 1. 先睹为快
3+
### 2. 实现原理
4+
#### 2.1 新建项目
5+
#### 2.2 创建maven目录结构,以及pom.xml文件
6+
#### 2.3 pom.xml文件中加入依赖
7+
```xml
8+
<parent>
9+
<groupId>org.springframework.boot</groupId>
10+
<artifactId>spring-boot-starter-parent</artifactId>
11+
<version>2.0.5.RELEASE</version>
12+
<relativePath/>
13+
</parent>
14+
```
15+
#### 2.4 pom.xml文件中加入springboot-starter依赖
16+
```xml
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.oven</groupId>
20+
<artifactId>springboot_dubbo_common_api</artifactId>
21+
<version>${project.version}</version>
22+
</dependency>
23+
</dependencies>
24+
```
25+
#### 2.5 pom.xml文件中加入maven-springboot打包插件
26+
```xml
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-maven-plugin</artifactId>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
```
36+
#### 2.6 开发启动类
37+
```java
38+
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
39+
import org.springframework.boot.SpringApplication;
40+
import org.springframework.boot.autoconfigure.SpringBootApplication;
41+
42+
@EnableDubbo
43+
@SpringBootApplication
44+
public class Application {
45+
46+
public static void main(String[] args) {
47+
SpringApplication.run(Application.class, args);
48+
}
49+
50+
}
51+
```
52+
#### 2.7 开发测试接口类
53+
```java
54+
import com.oven.service.DemoService;
55+
import org.apache.dubbo.config.annotation.Reference;
56+
import org.springframework.web.bind.annotation.RequestMapping;
57+
import org.springframework.web.bind.annotation.RestController;
58+
59+
@RestController
60+
public class DemoController {
61+
62+
@Reference(version = "1.0.0")
63+
private DemoService demoService;
64+
65+
@RequestMapping("/test")
66+
public String test(String name) {
67+
return demoService.sayHello(name);
68+
}
69+
70+
}
71+
```
72+
#### 2.8 编辑配置文件
73+
```properties
74+
server.port=8081
75+
dubbo.application.id=client
76+
dubbo.registry.address=zookeeper://172.16.188.194:2181
77+
```
78+
#### 2.9 编译打包运行
79+
### 3. 应用场景
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.oven;
2+
3+
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@EnableDubbo
8+
@SpringBootApplication
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.oven.controller;
2+
3+
import com.oven.service.DemoService;
4+
import org.apache.dubbo.config.annotation.Reference;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@RestController
9+
public class DemoController {
10+
11+
@Reference(version = "1.0.0")
12+
private DemoService demoService;
13+
14+
@RequestMapping("/test")
15+
public String test(String name) {
16+
return demoService.sayHello(name);
17+
}
18+
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
server.port=8081
2+
dubbo.application.id=client
3+
dubbo.registry.address=zookeeper://172.16.188.194:2181
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>springboot_dubbo</artifactId>
7+
<groupId>com.oven</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>springboot_dubbo_common_api</artifactId>
13+
14+
15+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.oven.service;
2+
3+
public interface DemoService {
4+
5+
String sayHello(String name);
6+
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>springboot_dubbo</artifactId>
7+
<groupId>com.oven</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>springboot_dubbo_server</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.oven</groupId>
17+
<artifactId>springboot_dubbo_common_api</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
</dependencies>
21+
22+
</project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# springboot炖dubbo-server
2+
### 1. 先睹为快
3+
### 2. docker安装kafka
4+
#### 2.1 下载zookeeper镜像
5+
```shell script
6+
docker pull wurstmeister/zookeeper
7+
```
8+
#### 2.2 启动zookeeper容器
9+
```shell script
10+
docker run -d --name myzookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime wurstmeister/zookeeper
11+
```
12+
### 3. 实现原理
13+
#### 3.1 新建项目
14+
#### 3.2 创建maven目录结构,以及pom.xml文件
15+
#### 3.3 pom.xml文件中加入依赖
16+
```xml
17+
<parent>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-parent</artifactId>
20+
<version>2.0.5.RELEASE</version>
21+
<relativePath/>
22+
</parent>
23+
```
24+
#### 3.4 pom.xml文件中加入springboot-starter依赖
25+
```xml
26+
<dependencies>
27+
<dependency>
28+
<groupId>com.oven</groupId>
29+
<artifactId>springboot_dubbo_common_api</artifactId>
30+
<version>${project.version}</version>
31+
</dependency>
32+
</dependencies>
33+
```
34+
#### 3.5 pom.xml文件中加入maven-springboot打包插件
35+
```xml
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-maven-plugin</artifactId>
41+
</plugin>
42+
</plugins>
43+
</build>
44+
```
45+
#### 3.6 开发启动类
46+
```java
47+
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
48+
import org.springframework.boot.SpringApplication;
49+
import org.springframework.boot.autoconfigure.SpringBootApplication;
50+
51+
@EnableDubbo
52+
@SpringBootApplication
53+
public class Application {
54+
55+
public static void main(String[] args) {
56+
SpringApplication.run(Application.class, args);
57+
}
58+
59+
}
60+
```
61+
#### 3.7 开发服务接口实现类
62+
```java
63+
import com.oven.service.DemoService;
64+
import org.apache.dubbo.config.annotation.Service;
65+
66+
@Service(version = "1.0.0")
67+
public class DemoServiceImpl implements DemoService {
68+
69+
@Override
70+
public String sayHello(String name) {
71+
return "hello " + name;
72+
}
73+
74+
}
75+
```
76+
#### 3.8 编辑配置文件
77+
```properties
78+
dubbo.application.id=server
79+
dubbo.registry.address=zookeeper://172.16.188.194:2181
80+
```
81+
#### 3.9 编译打包运行
82+
### 4. 应用场景

0 commit comments

Comments
 (0)