增加 spring cloud alibaba dubbo 服务调用的示例

This commit is contained in:
YunaiV
2020-02-23 18:26:53 +08:00
parent fc989934e9
commit 3ff65ce544
5 changed files with 17 additions and 15 deletions

View File

@@ -50,6 +50,13 @@
</dependencyManagement>
<dependencies>
<!-- 引入定义的 Dubbo API 接口 -->
<dependency>
<groupId>cn.iocoder.springboot.labs</groupId>
<artifactId>labx-07-sca-dubbo-demo02-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -73,13 +80,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.springboot.labs</groupId>
<artifactId>labx-07-sca-dubbo-demo02-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "demo-provider")
@DubboTransported(protocol = "dubbo")
//@DubboTransported(protocol = "rest")
// @DubboTransported(protocol = "rest")
public interface UserFeignClient {
/**

View File

@@ -77,7 +77,8 @@
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions> <!-- TODO 补充 https://stackoverflow.com/questions/48432225/nested-exception-is-java-lang-nosuchmethoderror-javax-ws-rs-clienterrorexceptio -->
<exclusions>
<!-- 参考文章 https://stackoverflow.com/questions/48432225/nested-exception-is-java-lang-nosuchmethoderror-javax-ws-rs-clienterrorexceptio -->
<exclusion>
<artifactId>jsr311-api</artifactId>
<groupId>javax.ws.rs</groupId>
@@ -91,7 +92,7 @@
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
<!-- 引入 Dubbo Rest 协议相关的 依赖 -->
<!-- 引入 Dubbo Rest 协议相关的依赖 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-netty4</artifactId>

View File

@@ -10,12 +10,12 @@ import javax.ws.rs.core.MediaType;
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
@org.apache.dubbo.config.annotation.Service(version = "1.0.0", protocol = {"dubbo", "rest"})
@Path("/")
@Path("/user")
public class UserServiceImpl implements UserService {
@Override
@GET
@Path("/user/get")
@Path("/get")
@Produces(APPLICATION_JSON_VALUE)
public UserDTO get(@QueryParam("id") Integer id) {
return new UserDTO().setId(id)
@@ -25,7 +25,7 @@ public class UserServiceImpl implements UserService {
@Override
@POST
@Path("/user/add")
@Path("/add")
@Consumes(MediaType.APPLICATION_JSON)
public Integer add(UserAddDTO addDTO) {
return (int) (System.currentTimeMillis() / 1000); // 嘿嘿,随便返回一个 id

View File

@@ -7,10 +7,11 @@ import org.springframework.web.bind.annotation.*;
@org.apache.dubbo.config.annotation.Service(version = "1.0.0", protocol = {"dubbo"})
@RestController
@RequestMapping("/user")
public class UserServiceImpl implements UserService {
@Override
@GetMapping("/user/get")
@GetMapping("/get")
public UserDTO get(@RequestParam("id") Integer id) {
return new UserDTO().setId(id)
.setName("没有昵称:" + id)
@@ -18,7 +19,7 @@ public class UserServiceImpl implements UserService {
}
@Override
@PostMapping("/user/add")
@PostMapping("/add")
public Integer add(@RequestBody UserAddDTO addDTO) {
return (int) (System.currentTimeMillis() / 1000); // 嘿嘿,随便返回一个 id
}