代码的链接地址:https://gitee.com/frostGG/springbooo_dubbo_demo.git

  1、项目的目录经构:

  介绍:

    这一个项目,用的是阿里的dubbo,和zookeeper,来进行分布式配置的,所以以上两个没有安装的可以先去网上安装一下,还有我自己用的这两个是虚拟机上面的,你自己用的时候,可以改一下zookeeper的地址就行了。

  下面开始代码:(新测可用的,可以直接复制下来就行了)

  父类pom文件的依赖:

  1.      <!--对全栈web开发的支持,包括Tomcat和 spring-webmvc-->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6.  
  7. <!--对测试的支持-->
  8. <dependency>
  9. <groupId>org.springframework.boot</groupId>
  10. <artifactId>spring-boot-starter-test</artifactId>
  11. <scope>test</scope>
  12. </dependency>
  13.  
  14. <!-- 热启动 -->
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-devtools</artifactId>
  18. <scope>runtime</scope>
  19. <optional>true</optional>
  20. </dependency>
  21.  
  22. <!--lang -->
  23. <dependency>
  24. <groupId>org.apache.commons</groupId>
  25. <artifactId>commons-lang3</artifactId>
  26. <version>3.4</version>
  27. </dependency>
  28.  
  29. <!--lombok-->
  30. <dependency>
  31. <groupId>org.projectlombok</groupId>
  32. <artifactId>lombok</artifactId>
  33. </dependency>

(上面所有的依赖,都是全项目都可以用的,所有提取出来放在这里,其实前三个也可以不用加进来,把前三个加到服务端和客户端里面就行了)

下面是服务端的pom文件 和 yml 文件:

  1. <dependency>
  2. <groupId>com.frost</groupId>
  3. <artifactId>student_entity</artifactId>
  4. <version>1.0-SNAPSHOT</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.frost</groupId>
  8. <artifactId>student_api</artifactId>
  9. <version>1.0-SNAPSHOT</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>com.frost</groupId>
  13. <artifactId>student_mapper</artifactId>
  14. <version>1.0-SNAPSHOT</version>
  15. </dependency>
  16. <!--Spring boot 和 dubbo 结和-->
  17. <dependency>
  18. <groupId>com.alibaba.boot</groupId>
  19. <artifactId>dubbo-spring-boot-starter</artifactId>
  20. <version>0.2.</version>
  21. </dependency>
  22.  
  23. <!--Zookeeper 开源客户端-->
  24. <dependency>
  25. <groupId>org.apache.curator</groupId>
  26. <artifactId>curator-framework</artifactId>
  27. <version>4.0.</version>
  28. </dependency>
  29.  
  30. <!--zookeeper-->
  31. <dependency>
  32. <groupId>org.apache.zookeeper</groupId>
  33. <artifactId>zookeeper</artifactId>
  34. <version>3.4.</version>
  35. </dependency>

(前面三个依赖是本项目中引入的依赖)

yml 文件:

  1. server:
  2. port:
  3.  
  4. #配置日志
  5. logging:
  6. level:
  7. com.frost: debug # 配置日志级别
  8. path: "D:/test" #配置日志输出的文件路径
  9.  
  10. # dubbo 配置
  11. dubbo:
  12. application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
  13. name: student-service
  14. registry: #注册中心配置,用于配置连接注册中心相关信息。
  15. address: zookeeper://192.168.25.128:2181
  16. protocol: #协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
  17. name: dubbo
  18. port:
  19. scan:
  20. base-packages: com.frost.service.impl
  21. version: 1.0.
  22.  
  23. # Spring 配置
  24. spring:
  25. application:
  26. name: student-service
  27. datasource:
  28. # mysql
  29. driver-class-name: com.mysql.jdbc.Driver
  30. url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
  31. username: root
  32. password: root
  33.  
  34. # mybatis 配置
  35. mybatis:
  36. # 映射文件
  37. mapper-locations: classpath:mapper/*.xml
  38. # 实体娄
  39. type-aliases-package: com.frost.entity
  40. configuration:
  41. # 自动开启大小写转换
  42. map-underscore-to-camel-case: true
  43.  
  44. # 分页信息
  45. pagehelper:
  46. supportMethodsArguments: true
  47. reasonable: true
  48. helperDialect: mysql
  49. params: count=countSql

下面是客户端的pom文件和yml文件:

  1.      <dependency>
  2. <groupId>com.frost</groupId>
  3. <artifactId>student_entity</artifactId>
  4. <version>1.0-SNAPSHOT</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.frost</groupId>
  8. <artifactId>student_api</artifactId>
  9. <version>1.0-SNAPSHOT</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>com.frost</groupId>
  13. <artifactId>student_common</artifactId>
  14. <version>1.0-SNAPSHOT</version>
  15. </dependency>
  16.  
  17. <!--分页插件-->
  18. <!--<dependency>
  19. <groupId>com.github.pagehelper</groupId>
  20. <artifactId>pagehelper-spring-boot-starter</artifactId>
  21. <version>1.2.</version>
  22. </dependency>-->
  23.  
  24. <!--Spring boot 和 dubbo 结和-->
  25. <dependency>
  26. <groupId>com.alibaba.boot</groupId>
  27. <artifactId>dubbo-spring-boot-starter</artifactId>
  28. <version>0.2.</version>
  29. </dependency>
  30.  
  31. <!--Zookeeper 开源客户端-->
  32. <dependency>
  33. <groupId>org.apache.curator</groupId>
  34. <artifactId>curator-framework</artifactId>
  35. <version>4.0.</version>
  36. </dependency>
  37.  
  38. <!--zookeeper-->
  39. <dependency>
  40. <groupId>org.apache.zookeeper</groupId>
  41. <artifactId>zookeeper</artifactId>
  42. <version>3.4.</version>
  43. </dependency>

(前三个也是本项目的依赖)

yml文件:

  1. server:
  2. port:
  3.  
  4. # Spring 配置
  5. spring:
  6. application:
  7. name: student-client
  8.  
  9. # dubbo 配置
  10. dubbo:
  11. application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
  12. name: student-client
  13. registry: #注册中心配置,用于配置连接注册中心相关信息。
  14. address: zookeeper://192.168.25.128:2181
  15. protocol: #协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
  16. name: dubbo
  17. port:
  18. version: 1.0.

下面是数据访问层的pom依赖:

  1.      <dependency>
  2. <groupId>com.frost</groupId>
  3. <artifactId>student_entity</artifactId>
  4. <version>1.0-SNAPSHOT</version>
  5. </dependency>
  6.  
  7. <!--mysql-->
  8. <dependency>
  9. <groupId>mysql</groupId>
  10. <artifactId>mysql-connector-java</artifactId>
  11. </dependency>
  12. <!--分页插件-->
  13. <dependency>
  14. <groupId>com.github.pagehelper</groupId>
  15. <artifactId>pagehelper-spring-boot-starter</artifactId>
  16. <version>1.2.</version>
  17. </dependency>
  18. <!--mybatis-->
  19. <dependency>
  20. <groupId>org.mybatis.spring.boot</groupId>
  21. <artifactId>mybatis-spring-boot-starter</artifactId>
  22. <version>1.3.</version>
  23. </dependency>
  24. <!--德鲁依数据库-->
  25. <dependency>
  26. <groupId>com.alibaba</groupId>
  27. <artifactId>druid</artifactId>
  28. <version>1.1.</version>
  29. </dependency>
  30.  
  31. <!--日志-->
  32. <dependency>
  33. <groupId>log4j</groupId>
  34. <artifactId>log4j</artifactId>
  35. <version>1.2.</version>
  36. </dependency>

代码生成器的插件:

  1.   <build>
  2. <plugins>
  3. <!--逆向工程-->
  4. <plugin>
  5. <groupId>org.mybatis.generator</groupId>
  6. <artifactId>mybatis-generator-maven-plugin</artifactId>
  7. <version>1.3.</version>
  8. <configuration>
  9. <verbose>true</verbose>
  10. <overwrite>false</overwrite>
  11. </configuration>
  12. <dependencies>
  13. <!--mysql-->
  14. <dependency>
  15. <groupId>mysql</groupId>
  16. <artifactId>mysql-connector-java</artifactId>
  17. <version>5.1.</version>
  18. </dependency>
  19. <!--oracle-->
  20. <!--<dependency>
  21. <groupId>cn.easyproject</groupId>
  22. <artifactId>ojdbc6</artifactId>
  23. <version>12.1.0.2.</version>
  24. </dependency>-->
  25. </dependencies>
  26. </plugin>
  27. </plugins>
  28. </build>

这里其实有一个我以前的一篇:https://www.cnblogs.com/xdtg/p/11748028.html

  写dubbo项目主要的注意点是:服务端里面的 @service(version = "1.0.0")应该引用的是 dubbo提供的,不用spring boot 自己的,然后注入的时候,用@Reference(version = "1.0.0")来进行注入。加上版本号是防止报很多莫名其妙的错误!

  然后我自己感觉不好理解的地方是在服务端里面扫描mapper接口,并且配置mybatis,这里是因为在服务端里面引入了持久层的东西,并且mybatis也支持多服务配置,并且还在yml文件里面配置了:

所以可以跨服务调用。并且接口也是在服务端里面配置扫描的。

  细节决定成败!个人愚见,如有不对,恳请扶正!

Spring boot + mybatis + dubbo + zookeeper + mysql + mybatis-generator 一个小demo的更多相关文章

  1. Spring Boot 项目学习 (二) MySql + MyBatis 注解 + 分页控件 配置

    0 引言 本文主要在Spring Boot 基础项目的基础上,添加 Mysql .MyBatis(注解方式)与 分页控件 的配置,用于协助完成数据库操作. 1 创建数据表 这个过程就暂时省略了. 2 ...

  2. Spring Boot入门(六):使用MyBatis访问MySql数据库(注解方式)

    本系列博客记录自己学习Spring Boot的历程,如帮助到你,不胜荣幸,如有错误,欢迎指正! 本篇博客我们讲解下在Spring Boot中使用MyBatis访问MySql数据库的简单用法. 1.前期 ...

  3. Spring Boot(六):如何使用mybatis

    Spring Boot(六):如何使用mybatis orm框架的本质是简化编程中操作数据库的编码,发展到现在基本上就剩两家了,一个是宣称可以不用写一句SQL的hibernate,一个是可以灵活调试动 ...

  4. Spring Boot (七): Mybatis极简配置

    Spring Boot (七): Mybatis极简配置 1. 前言 ORM 框架的目的是简化编程中的数据库操作,经过这么多年的发展,基本上活到现在的就剩下两家了,一个是宣称可以不用写 SQL 的 H ...

  5. Spring Boot (八): Mybatis 增强工具 MyBatis-Plus

    1. 简介 在上一篇文章<Spring Boot (七): Mybatis极简配置> 中我们介绍了在 Spring Boot 中 Mybatis 的基础使用方式,其中有一部分美中不足的是 ...

  6. Spring Boot 2.X(五):MyBatis 多数据源配置

    前言 MyBatis 多数据源配置,最近在项目建设中,需要在原有系统上扩展一个新的业务模块,特意将数据库分库,以便减少复杂度.本文直接以简单的代码示例,如何对 MyBatis 多数据源配置. 准备 创 ...

  7. Spring Boot 整合 Dubbo和Zookeeper

    Spring Boot 整合 Dubbo和Zookeeper Spring Boot 整合 Dubbo和Zookeeper 环境介绍 Zookeeper 安装 启动 Dubbo admin 搭建 创建 ...

  8. Spring Boot整合Dubbo框架demo

    Dubbo框架原理见之前的博文:http://www.cnblogs.com/umgsai/p/5836925.html 首先启动zookeeper Server端 Pom配置如下 <?xml ...

  9. Spring Boot和Dubbo整合

    provider端 POM依赖 <dependencies> <dependency> <groupId>org.springframework.boot</ ...

随机推荐

  1. 2.Shell脚本中的set指令,比如set -x 和 set -e

    set参数介绍 set指令能设置所使用shell的执行方式,可依照不同的需求来做设置 -a 标示已修改的变量,以供输出至环境变量. -b 使被中止的后台程序立刻回报执行状态. -C 转向所产生的文件无 ...

  2. 在Go1.11.1中使用go module管理依赖

    今天试验了一下go的版本管理Go moule,只是安装了下,由于目前还没有进行大的项目开发,暂时没有碰到坑. 使用了模块后,可以不用在GOPATH中再建立src目录了,直接在GOPATH中就行 另外, ...

  3. 搞Jedis案例出现问题,有大佬帮我看看怎么解决吗?先感谢大佬点进来看了---Day31

    今天学了Jedis的相关内容,然后做了一个案例,但是出现了错误,然后我百度了一晚上没有解决,想到看看发个博客能不能有大佬帮我看一下问题出现在哪里,百度了一晚上有点懵逼.求大佬帮我解决,在这小弟我先万分 ...

  4. 0 != null 为什么报指针?

    大家好,这是我第一次写博客,来分享我平时工作中遇到的问题及平时学习的技术,如果有写的不好或者不对的地方还望大家能够指出和包涵. 那么接下来就开始说下我工作中遇到的这个问题,我写了一个test,如下: ...

  5. C# 构造基础返回值类型-BaseResponse

    学无止境,精益求精 十年河东,十年河西,莫欺少年穷 用于基础返回值类型,如下: using System; using System.Collections.Generic; using System ...

  6. MySQL语言分类——DDL

    DDL的全称Data Definition Language,即数据定义语言 DDL的语法有:create.alter.drop.rename.truncate.对此做一个详细的解释: create ...

  7. springMVC对RESTful的支持

    1:后台controller方法编写 @RequestMapping("/itemsLook/{id}") public ItemsCustom itemsLook(@PathVa ...

  8. 监控微信小程序中的慢HTTP请求

    摘要: 请求时间太长,影响用户体验,使用 Fundebug 监控慢请求. Fundebug 的微信小程序监控插件在 0.5.0 版本已经支持监控 HTTP 请求错误,在小程序中通过wx.request ...

  9. Android 自定义ListView动态加载数据

    我们都知道网络取数据是耗时操作,如果我们一次性请求所有数据,假如数据量不多那还可以接受,但是如果数据量特别多,那么带来的后果就是用户的愤怒(用户是很没有耐心的),所以这时候我们就需要动态的加载数据,分 ...

  10. 基于Spring Boot的注解驱动式公众号极速开发框架FastBootWeixin

    本框架基于Spring Boot实现,使用注解完成快速开发,可以快速的完成一个微信公众号,重新定义公众号开发. 在使用本框架前建议对微信公众号开发文档有所了解,不过在不了解公众号文档的情况下使用本框架 ...