Browse Source

更新 TODO.md

v-1.5.x
Yangkai.Shen 7 years ago
parent
commit
74746d7cdd
18 changed files with 756 additions and 1 deletions
  1. +1
    -1
      TODO.md
  2. +25
    -0
      spring-boot-demo-dubbo-parent/.gitignore
  3. +116
    -0
      spring-boot-demo-dubbo-parent/README.md
  4. +74
    -0
      spring-boot-demo-dubbo-parent/pom.xml
  5. +165
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md
  6. +35
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml
  7. +12
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java
  8. +33
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java
  9. +18
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java
  10. +30
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java
  11. +14
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml
  12. +16
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java
  13. +106
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md
  14. +36
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml
  15. +12
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java
  16. +32
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java
  17. +15
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml
  18. +16
    -0
      spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java

+ 1
- 1
TODO.md View File

@@ -37,7 +37,7 @@
- [ ] spring-boot-demo-urule(集成 urule 实现规则引擎)
- [ ] spring-boot-demo-activiti(集成 Activiti 实现流程控制引擎)
- [ ] spring-boot-demo-async(Spring boot 实现异步调用)
- [ ] spring-boot-demo-dubbo(集成 dubbo)
- [x] ~~spring-boot-demo-dubbo(集成 dubbo)~~
- [x] ~~spring-boot-demo-war(打包成war包)~~
- [x] ~~spring-boot-demo-elasticsearch(集成 ElasticSearch,使用原生操作 ES 的方式)~~



+ 25
- 0
spring-boot-demo-dubbo-parent/.gitignore View File

@@ -0,0 +1,25 @@
/target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

+ 116
- 0
spring-boot-demo-dubbo-parent/README.md View File

@@ -0,0 +1,116 @@
# spring-boot-demo-dubbo-parent

依赖 [非官方的spring-boot-starter-dubbo](https://gitee.com/reger/spring-boot-starter-dubbo)

更新 springboot 版本为 2.0.1.RELEASE

本身是个父依赖,包含了3个 module

| 名称 | 作用 |
| :----------------------------------------------------------- | :-------------------------------------- |
| [spring-boot-demo-dubbo-api](./spring-boot-demo-dubbo-api/pom.xml) | Spring Boot 与 Dubbo 整合抽取的服务接口 |
| [spring-boot-demo-dubbo-provider](./spring-boot-demo-dubbo-provider/pom.xml) | Spring Boot 与 Dubbo 整合服务的提供方 |
| [spring-boot-demo-dubbo-consumer](./spring-boot-demo-dubbo-consumer/pom.xml) | Spring Boot 与 Dubbo 整合服务的消费方 |

### pom.xml

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>spring-boot-demo-dubbo-parent</name>
<description>Spring Boot 与 Dubbo 整合的父依赖</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<modules>
<module>spring-boot-demo-dubbo-api</module>
<module>spring-boot-demo-dubbo-provider</module>
<module>spring-boot-demo-dubbo-consumer</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot-starter-dubbo.version>1.1.1</spring-boot-starter-dubbo.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.gitee.reger</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>${spring-boot-starter-dubbo.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
```

### 步骤

1. 启动本地的 `Zookeeper` 服务,端口号为 **2181**

> 这里 `Zookeeper` 可以直接使用单机版,如果需要配置集群版的,可以参考 http://xkcoding.com/2017/11/01/zookeeper-cluster.html

2. 启动两个 `spring-boot-demo-dubbo-provider` 程序,端口号分别使用 **8082**、**8083**

3. 启动 `spring-boot-demo-dubbo-consumer` 程序,端口号为 **9090**

4. 浏览器输入 http://localhost:9090/greet?name=test

可以看到,**8082**和**8083**端口随机打印

> Hello, test, from port: 8082


> Hello, test, from port: 8083

5. 本地启动 `dubbo-admin` 可以查看服务提供方和消费方,也可以配置负载均衡策略等等

> 关于 `dubbo-admin` 的安装和配置等,可以参考 http://xkcoding.com/2017/11/08/dubbo-admin-install.html

+ 74
- 0
spring-boot-demo-dubbo-parent/pom.xml View File

@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>spring-boot-demo-dubbo-parent</name>
<description>Spring Boot 与 Dubbo 整合的父依赖</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<modules>
<module>spring-boot-demo-dubbo-api</module>
<module>spring-boot-demo-dubbo-provider</module>
<module>spring-boot-demo-dubbo-consumer</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot-starter-dubbo.version>1.1.1</spring-boot-starter-dubbo.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.gitee.reger</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>${spring-boot-starter-dubbo.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

+ 165
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md View File

@@ -0,0 +1,165 @@
# spring-boot-demo-dubbo-consumer

Spring Boot 与 Dubbo 整合服务的消费方

依赖 [spring-boot-demo-dubbo-api](../spring-boot-demo-dubbo-api/pom.xml)

### pom.xml

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-boot-demo-dubbo-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-boot-demo-dubbo-consumer</name>
<description>Spring Boot 与 Dubbo 整合服务的消费方</description>
<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
```

### application.yml

```yaml
server:
port: 9090
spring:
dubbo:
application:
name: dubbo-consumer
base-package: com.xkcoding.springbootdemodubboconsumer.service # dubbo服务调用者所在的包
registry:
address: 127.0.0.1 # zookeeper注册中心的地址
port: 2181 # zookeeper注册中心的端口
consumer:
timeout: 1000
check: true # 服务启动时检查被调用服务是否可用
retries: 2
```

### GreetController.java

```java
package com.xkcoding.springbootdemodubboconsumer.controller;

import com.xkcoding.springbootdemodubboconsumer.service.GreetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* GreetController
* </p>
*
* @package: com.xkcoding.springbootdemodubboconsumer.controller
* @description: GreetController
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:29
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
@RestController
@RequestMapping("/greet")
public class GreetController {
@Autowired
private GreetService greetService;

@GetMapping("")
public String hello(@RequestParam String name) {
return greetService.greeting(name);
}
}
```

### GreetService.java

```java
package com.xkcoding.springbootdemodubboconsumer.service;

/**
* <p>
* GreetService
* </p>
*
* @package: com.xkcoding.springbootdemodubboconsumer.service
* @description: GreetService
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:30
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
public interface GreetService {
String greeting(String name);
}
```

### GreetServiceImpl.java

代码中的 `@Service` 使用的是 `Spring` 的注解,而不是 `Dubbo` 的注解

代码中的 `@Inject` 可以替换成 `Dubbo` 提供的 `@Reference`,效果相同

```java
package com.xkcoding.springbootdemodubboconsumer.service.impl;

import com.reger.dubbo.annotation.Inject;
import com.xkcoding.springbootdemodubboapi.service.HelloService;
import com.xkcoding.springbootdemodubboconsumer.service.GreetService;
import org.springframework.stereotype.Service;

/**
* <p>
* GreetServiceImpl
* </p>
*
* @package: com.xkcoding.springbootdemodubboconsumer.service.impl
* @description: GreetServiceImpl
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:31
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
@Service
public class GreetServiceImpl implements GreetService {
@Inject
private HelloService helloService;

@Override
public String greeting(String name) {
return helloService.hello(name);
}
}
```


+ 35
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-boot-demo-dubbo-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-boot-demo-dubbo-consumer</name>
<description>Spring Boot 与 Dubbo 整合服务的消费方</description>
<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

+ 12
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java View File

@@ -0,0 +1,12 @@
package com.xkcoding.springbootdemodubboconsumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootDemoDubboConsumerApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootDemoDubboConsumerApplication.class, args);
}
}

+ 33
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java View File

@@ -0,0 +1,33 @@
package com.xkcoding.springbootdemodubboconsumer.controller;

import com.xkcoding.springbootdemodubboconsumer.service.GreetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* GreetController
* </p>
*
* @package: com.xkcoding.springbootdemodubboconsumer.controller
* @description: GreetController
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:29
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
@RestController
@RequestMapping("/greet")
public class GreetController {
@Autowired
private GreetService greetService;

@GetMapping("")
public String hello(@RequestParam String name) {
return greetService.greeting(name);
}
}

+ 18
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java View File

@@ -0,0 +1,18 @@
package com.xkcoding.springbootdemodubboconsumer.service;

/**
* <p>
* GreetService
* </p>
*
* @package: com.xkcoding.springbootdemodubboconsumer.service
* @description: GreetService
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:30
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
public interface GreetService {
String greeting(String name);
}

+ 30
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java View File

@@ -0,0 +1,30 @@
package com.xkcoding.springbootdemodubboconsumer.service.impl;

import com.reger.dubbo.annotation.Inject;
import com.xkcoding.springbootdemodubboapi.service.HelloService;
import com.xkcoding.springbootdemodubboconsumer.service.GreetService;
import org.springframework.stereotype.Service;

/**
* <p>
* GreetServiceImpl
* </p>
*
* @package: com.xkcoding.springbootdemodubboconsumer.service.impl
* @description: GreetServiceImpl
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:31
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
@Service
public class GreetServiceImpl implements GreetService {
@Inject
private HelloService helloService;

@Override
public String greeting(String name) {
return helloService.hello(name);
}
}

+ 14
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml View File

@@ -0,0 +1,14 @@
server:
port: 9090
spring:
dubbo:
application:
name: dubbo-consumer
base-package: com.xkcoding.springbootdemodubboconsumer.service # dubbo服务调用者所在的包
registry:
address: 127.0.0.1 # zookeeper注册中心的地址
port: 2181 # zookeeper注册中心的端口
consumer:
timeout: 1000
check: true # 服务启动时检查被调用服务是否可用
retries: 2

+ 16
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java View File

@@ -0,0 +1,16 @@
package com.xkcoding.springbootdemodubboconsumer;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootDemoDubboConsumerApplicationTests {

@Test
public void contextLoads() {
}

}

+ 106
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md View File

@@ -0,0 +1,106 @@
# spring-boot-demo-dubbo-provider

Spring Boot 与 Dubbo 整合服务的提供方

依赖 [spring-boot-demo-dubbo-api](../spring-boot-demo-dubbo-api/pom.xml)

### pom.xml

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-boot-demo-dubbo-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-boot-demo-dubbo-provider</name>
<description>Spring Boot 与 Dubbo 整合服务的提供方</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
```

### application.yml

```yaml
server:
port: 8082
spring:
dubbo:
application:
name: dubbo-provider
base-package: com.xkcoding.springbootdemodubboprovider.service # dubbo服务发布者所在的包
registry:
address: 127.0.0.1 # zookeeper注册中心的地址
port: 2181 # zookeeper注册中心的端口
protocol:
name: dubbo
serialization: hessian2
provider:
retries: 0
```

### HelloServiceImpl.java

代码中的 `@Service` 使用的是 `Dubbo` 的注解,而不是 `Spring` 的注解

```java
package com.xkcoding.springbootdemodubboprovider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xkcoding.springbootdemodubboapi.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;

/**
* <p>
* HelloServiceImpl
* </p>
*
* @package: com.xkcoding.springbootdemodubboprovider.service.impl
* @description: HelloServiceImpl
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:24
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
@Service
@Slf4j
public class HelloServiceImpl implements HelloService {
@Value("${server.port}")
private Integer port;

@Override
public String hello(String name) {
log.info("Hello, {}, from port: {}",name, port);
return "Hello, " + name + ", from port: " + port;
}
}
```


+ 36
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-boot-demo-dubbo-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-boot-demo-dubbo-provider</name>
<description>Spring Boot 与 Dubbo 整合服务的提供方</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

+ 12
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java View File

@@ -0,0 +1,12 @@
package com.xkcoding.springbootdemodubboprovider;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootDemoDubboProviderApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootDemoDubboProviderApplication.class, args);
}
}

+ 32
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java View File

@@ -0,0 +1,32 @@
package com.xkcoding.springbootdemodubboprovider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xkcoding.springbootdemodubboapi.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;

/**
* <p>
* HelloServiceImpl
* </p>
*
* @package: com.xkcoding.springbootdemodubboprovider.service.impl
* @description: HelloServiceImpl
* @author: yangkai.shen
* @date: Created in 2018/4/17 下午5:24
* @copyright: Copyright (c) 2018
* @version: V1.0
* @modified: yangkai.shen
*/
@Service
@Slf4j
public class HelloServiceImpl implements HelloService {
@Value("${server.port}")
private Integer port;

@Override
public String hello(String name) {
log.info("Hello, {}, from port: {}",name, port);
return "Hello, " + name + ", from port: " + port;
}
}

+ 15
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml View File

@@ -0,0 +1,15 @@
server:
port: 8082
spring:
dubbo:
application:
name: dubbo-provider
base-package: com.xkcoding.springbootdemodubboprovider.service # dubbo服务发布者所在的包
registry:
address: 127.0.0.1 # zookeeper注册中心的地址
port: 2181 # zookeeper注册中心的端口
protocol:
name: dubbo
serialization: hessian2
provider:
retries: 0

+ 16
- 0
spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java View File

@@ -0,0 +1,16 @@
package com.xkcoding.springbootdemodubboprovider;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootDemoDubboProviderApplicationTests {

@Test
public void contextLoads() {
}

}

Loading…
Cancel
Save