Skip to content

Commit a7f1e77

Browse files
committed
java/ee: add dubbo usage
1 parent 55f7cfb commit a7f1e77

File tree

16 files changed

+327
-0
lines changed

16 files changed

+327
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>boot-dubbo</artifactId>
7+
<groupId>cn.edu.ntu</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>dubbo-common</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>junit</groupId>
17+
<artifactId>junit</artifactId>
18+
<version>4.11</version>
19+
<scope>test</scope>
20+
</dependency>
21+
</dependencies>
22+
23+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cn.edu.ntu.service;
2+
3+
public interface HelloService {
4+
/**
5+
* 问好
6+
*
7+
* @param name 姓名
8+
* @return 问好
9+
*/
10+
String sayHello(String name);
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** 此 module 主要是用于公共部分, 主要存放工具类, 实体, 以及服务提供方/调用方的接口定义 */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cn.edu.ntu;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertTrue;
6+
7+
/** Unit test for simple App. */
8+
public class AppTest {
9+
/** Rigorous Test :-) */
10+
@Test
11+
public void shouldAnswerWithTrue() {
12+
assertTrue(true);
13+
}
14+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>boot-dubbo</artifactId>
7+
<groupId>cn.edu.ntu</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>dubbo-consumer</artifactId>
13+
14+
<name>dubbo-consumer</name>
15+
16+
17+
<dependencies>
18+
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>com.alibaba.spring.boot</groupId>
26+
<artifactId>dubbo-spring-boot-starter</artifactId>
27+
<version>${dubbo.starter.version}</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>${project.groupId}</groupId>
32+
<artifactId>dubbo-common</artifactId>
33+
<version>${project.version}</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>com.101tec</groupId>
38+
<artifactId>zkclient</artifactId>
39+
<version>${zkclient.version}</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.projectlombok</groupId>
44+
<artifactId>lombok</artifactId>
45+
<optional>true</optional>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-test</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
</dependencies>
54+
55+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cn.edu.ntu;
2+
3+
import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
/** Hello world! */
8+
@EnableDubboConfiguration
9+
@SpringBootApplication
10+
public class ConsumerApplication {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(ConsumerApplication.class, args);
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cn.edu.ntu.controller;
2+
3+
import cn.edu.ntu.service.HelloService;
4+
import com.alibaba.dubbo.config.annotation.Reference;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestParam;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
@Slf4j
12+
public class HelloController {
13+
@Reference private HelloService helloService;
14+
15+
@GetMapping("/sayHello")
16+
public String sayHello(@RequestParam(defaultValue = "xkcoding") String name) {
17+
log.info("i'm ready to call someone......");
18+
return helloService.sayHello(name);
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
server:
2+
port: 9091
3+
4+
spring:
5+
dubbo:
6+
application:
7+
name: dubbo-consumer
8+
registry: zookeeper://1.15.129.214:2181
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>boot-dubbo</artifactId>
7+
<groupId>cn.edu.ntu</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>dubbo-provider</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-web</artifactId>
18+
</dependency>
19+
20+
<dependency>
21+
<groupId>com.alibaba.spring.boot</groupId>
22+
<artifactId>dubbo-spring-boot-starter</artifactId>
23+
<version>${dubbo.starter.version}</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>${project.groupId}</groupId>
28+
<artifactId>dubbo-common</artifactId>
29+
<version>${project.version}</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>com.101tec</groupId>
34+
<artifactId>zkclient</artifactId>
35+
<version>${zkclient.version}</version>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.projectlombok</groupId>
40+
<artifactId>lombok</artifactId>
41+
<optional>true</optional>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-test</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
</dependencies>
50+
51+
</project>
52+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cn.edu.ntu;
2+
3+
import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
/** Hello world! */
8+
@EnableDubboConfiguration
9+
@SpringBootApplication
10+
public class ProviderApplication {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(ProviderApplication.class, args);
14+
}
15+
}

0 commit comments

Comments
 (0)