From ef903c61fad140c3347a407949306365547fe42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Thu, 18 May 2023 12:42:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:dubbo=E6=95=B4=E7=90=86springboot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dubbo-api/pom.xml | 36 ----------- .../kwan/shuyu/config/ZookeeperConfig.java | 20 ------ .../com/kwan/shuyu/enums/ResultConstant.java | 43 +++++++++++++ .../java/com/kwan/shuyu/pojo/Payload.java | 61 +++++++++++++++++++ dubbo-client/pom.xml | 30 +++++++++ .../kwan/shuyu/DubboClientApplication.java | 5 +- .../kwan/shuyu/controller/UserController.java | 16 ++--- .../src/main/resources/application.yml | 15 ++++- dubbo-server/pom.xml | 30 +++++++++ .../kwan/shuyu/DubboServerApplication.java | 5 +- .../shuyu/service/impl/UserServiceImpl.java | 6 +- .../src/main/resources/application.yml | 14 ++++- pom.xml | 29 --------- 13 files changed, 204 insertions(+), 106 deletions(-) delete mode 100644 dubbo-api/src/main/java/com/kwan/shuyu/config/ZookeeperConfig.java create mode 100644 dubbo-api/src/main/java/com/kwan/shuyu/enums/ResultConstant.java create mode 100644 dubbo-api/src/main/java/com/kwan/shuyu/pojo/Payload.java diff --git a/dubbo-api/pom.xml b/dubbo-api/pom.xml index 6daf7ee..3fb4fee 100644 --- a/dubbo-api/pom.xml +++ b/dubbo-api/pom.xml @@ -8,45 +8,9 @@ 1.0-SNAPSHOT 4.0.0 - dubbo-api - 8 8 - - - - org.apache.curator - curator-framework - 2.8.0 - - - org.apache.curator - curator-recipes - 2.8.0 - - - com.101tec - zkclient - 0.10 - - - slf4j-log4j12 - org.slf4j - - - zookeeper - org.apache.zookeeper - - - - - com.alibaba.spring.boot - dubbo-spring-boot-starter - 2.0.0 - - - \ No newline at end of file diff --git a/dubbo-api/src/main/java/com/kwan/shuyu/config/ZookeeperConfig.java b/dubbo-api/src/main/java/com/kwan/shuyu/config/ZookeeperConfig.java deleted file mode 100644 index 703c676..0000000 --- a/dubbo-api/src/main/java/com/kwan/shuyu/config/ZookeeperConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.kwan.shuyu.config; - - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; - -/** - * zookeeper的配置类 - * - * @author : qinyingjie - * @version : 2.2.0 - * @date : 2023/5/10 12:37 - */ -@Configuration -public class ZookeeperConfig { - - @Value("${kwan.zookeeper.hostlist}") - private String hostlist; - -} \ No newline at end of file diff --git a/dubbo-api/src/main/java/com/kwan/shuyu/enums/ResultConstant.java b/dubbo-api/src/main/java/com/kwan/shuyu/enums/ResultConstant.java new file mode 100644 index 0000000..756d18e --- /dev/null +++ b/dubbo-api/src/main/java/com/kwan/shuyu/enums/ResultConstant.java @@ -0,0 +1,43 @@ +package com.kwan.shuyu.enums; + +/** + * 结果集枚举 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/3/10 14:00 + */ +public enum ResultConstant { + /** + * 系统异常 + */ + ERROR("-1", "系统异常"), + /** + * ok + */ + SUCCESS("0", "ok"); + + private String code; + private String msg; + + private ResultConstant(String code, String msg) { + this.code = code; + this.msg = msg; + } + + public String getCode() { + return this.code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMsg() { + return this.msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/dubbo-api/src/main/java/com/kwan/shuyu/pojo/Payload.java b/dubbo-api/src/main/java/com/kwan/shuyu/pojo/Payload.java new file mode 100644 index 0000000..dec266f --- /dev/null +++ b/dubbo-api/src/main/java/com/kwan/shuyu/pojo/Payload.java @@ -0,0 +1,61 @@ +package com.kwan.shuyu.pojo; + +import com.kwan.shuyu.enums.ResultConstant; + +import java.io.Serializable; + +/** + * 结果集 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/3/13 14:45 + */ +public class Payload implements Serializable { + private static final long serialVersionUID = -1549643581827130116L; + private T payload; + private String code; + private String msg; + + public Payload() { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + } + + public Payload(T payload) { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + this.payload = payload; + } + + public Payload(String code, String msg) { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + this.code = code; + this.msg = msg; + } + + public Payload(T payload, String code, String msg) { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + this.payload = payload; + this.code = code; + this.msg = msg; + } + + public String getCode() { + return this.code; + } + + public String getMsg() { + return this.msg; + } + + public T getPayload() { + return this.payload; + } + + public boolean success() { + return this.getCode().equals("0"); + } +} \ No newline at end of file diff --git a/dubbo-client/pom.xml b/dubbo-client/pom.xml index a3ce1ff..9aaf5c3 100644 --- a/dubbo-client/pom.xml +++ b/dubbo-client/pom.xml @@ -21,5 +21,35 @@ dubbo-api 1.0-SNAPSHOT + + org.apache.curator + curator-framework + 5.2.1 + + + org.apache.curator + curator-recipes + 5.2.1 + + + org.apache.curator + curator-x-discovery + 5.2.1 + + + org.apache.dubbo + dubbo-spring-boot-starter + 3.0.7 + + + org.springframework.boot + spring-boot-starter + 2.0.6.RELEASE + + + org.springframework.boot + spring-boot-starter-web + 2.0.1.RELEASE + \ No newline at end of file diff --git a/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java b/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java index 896bb75..8f6c58a 100644 --- a/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java +++ b/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java @@ -1,11 +1,12 @@ package com.kwan.shuyu; -import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration; +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableDubbo @SpringBootApplication -@EnableDubboConfiguration //开启dubbo配置 public class DubboClientApplication { public static void main(String[] args) { SpringApplication.run(DubboClientApplication.class, args); diff --git a/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java b/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java index 2749e26..8e88b8e 100644 --- a/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java +++ b/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java @@ -1,21 +1,21 @@ package com.kwan.shuyu.controller; -import com.alibaba.dubbo.config.annotation.Reference; +import com.kwan.shuyu.pojo.Payload; import com.kwan.shuyu.service.UserService; -import org.springframework.stereotype.Controller; +import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController +@RequestMapping("/user") public class UserController { - @Reference(interfaceClass = UserService.class, version = "2.6.0", check = false) + @DubboReference(interfaceClass = UserService.class, check = false) private UserService userService; @RequestMapping("/count") - @ResponseBody - public String getCount() { + public Payload getCount() { int count = userService.getCount(); - return "当前在线的人数为:" + count; + return new Payload("当前在线的人数为:" + count); } } diff --git a/dubbo-client/src/main/resources/application.yml b/dubbo-client/src/main/resources/application.yml index feeb701..6b4af03 100644 --- a/dubbo-client/src/main/resources/application.yml +++ b/dubbo-client/src/main/resources/application.yml @@ -7,5 +7,16 @@ server: spring: application: name: dobbo-client - dubbo: - registry: zookeeper://120.79.36.53:2181 \ No newline at end of file + +dubbo: + protocol: + name: dubbo + port: 20881 + registry: + address: zookeeper://120.79.36.53:2181 + +management: + endpoints: + web: + exposure: + include: '*' diff --git a/dubbo-server/pom.xml b/dubbo-server/pom.xml index daec06b..60799cf 100644 --- a/dubbo-server/pom.xml +++ b/dubbo-server/pom.xml @@ -19,5 +19,35 @@ dubbo-api 1.0-SNAPSHOT + + org.apache.curator + curator-framework + 5.2.1 + + + org.apache.curator + curator-recipes + 5.2.1 + + + org.apache.curator + curator-x-discovery + 5.2.1 + + + org.apache.dubbo + dubbo-spring-boot-starter + 3.0.7 + + + org.springframework.boot + spring-boot-starter + 2.0.6.RELEASE + + + org.springframework.boot + spring-boot-starter-web + 2.0.1.RELEASE + \ No newline at end of file diff --git a/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java b/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java index fd22251..9da70bf 100644 --- a/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java +++ b/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java @@ -1,11 +1,12 @@ package com.kwan.shuyu; -import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +@EnableDubbo @SpringBootApplication -@EnableDubboConfiguration //开启dubbo配置 public class DubboServerApplication { public static void main(String[] args) { SpringApplication.run(DubboServerApplication.class, args); diff --git a/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java b/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java index dbfd4f8..3aab9fd 100644 --- a/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java +++ b/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java @@ -1,11 +1,9 @@ package com.kwan.shuyu.service.impl; -import com.alibaba.dubbo.config.annotation.Service; import com.kwan.shuyu.service.UserService; -import org.springframework.stereotype.Component; +import org.apache.dubbo.config.annotation.DubboService; -@Component -@Service(interfaceClass = UserService.class, version = "2.6.0", timeout = 15000) +@DubboService(interfaceClass = UserService.class) public class UserServiceImpl implements UserService { @Override diff --git a/dubbo-server/src/main/resources/application.yml b/dubbo-server/src/main/resources/application.yml index 94f7f76..daf51c0 100644 --- a/dubbo-server/src/main/resources/application.yml +++ b/dubbo-server/src/main/resources/application.yml @@ -7,6 +7,14 @@ server: spring: application: name: dobbo-service - dubbo: - server: true - registry: zookeeper://120.79.36.53:2181 \ No newline at end of file + +dubbo: + registry: + address: 120.79.36.53:2181,120.79.36.53:2182,120.79.36.53:2183 + protocol: zookeeper + +management: + endpoints: + web: + exposure: + include: '*' diff --git a/pom.xml b/pom.xml index 4ebb7c6..155d8e7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,6 @@ 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"> 4.0.0 - org.kwan.shuyu dubbo-demo pom @@ -17,32 +16,4 @@ 8 8 - - - org.springframework.boot - spring-boot-starter-web - 2.0.1.RELEASE - - - org.projectlombok - lombok - 1.16.10 - - - org.apache.commons - commons-io - 1.3.2 - - - org.apache.commons - commons-lang3 - 3.1 - - - com.alibaba - fastjson - 1.2.83 - - - \ No newline at end of file -- GitLab