Spring boot + mybatis + dubbo + zookeeper + mysql + mybatis-generator 一个小demo
代码的链接地址:https://gitee.com/frostGG/springbooo_dubbo_demo.git
1、项目的目录经构:
介绍:
这一个项目,用的是阿里的dubbo,和zookeeper,来进行分布式配置的,所以以上两个没有安装的可以先去网上安装一下,还有我自己用的这两个是虚拟机上面的,你自己用的时候,可以改一下zookeeper的地址就行了。
下面开始代码:(新测可用的,可以直接复制下来就行了)
父类pom文件的依赖:
- <!--对全栈web开发的支持,包括Tomcat和 spring-webmvc-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <!--对测试的支持-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- 热启动 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- <optional>true</optional>
- </dependency>
- <!--lang -->
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.4</version>
- </dependency>
- <!--lombok-->
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- </dependency>
(上面所有的依赖,都是全项目都可以用的,所有提取出来放在这里,其实前三个也可以不用加进来,把前三个加到服务端和客户端里面就行了)
下面是服务端的pom文件 和 yml 文件:
- <dependency>
- <groupId>com.frost</groupId>
- <artifactId>student_entity</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>com.frost</groupId>
- <artifactId>student_api</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>com.frost</groupId>
- <artifactId>student_mapper</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <!--Spring boot 和 dubbo 结和-->
- <dependency>
- <groupId>com.alibaba.boot</groupId>
- <artifactId>dubbo-spring-boot-starter</artifactId>
- <version>0.2.</version>
- </dependency>
- <!--Zookeeper 开源客户端-->
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <version>4.0.</version>
- </dependency>
- <!--zookeeper-->
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- <version>3.4.</version>
- </dependency>
(前面三个依赖是本项目中引入的依赖)
yml 文件:
- server:
- port:
- #配置日志
- logging:
- level:
- com.frost: debug # 配置日志级别
- path: "D:/test" #配置日志输出的文件路径
- # dubbo 配置
- dubbo:
- application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
- name: student-service
- registry: #注册中心配置,用于配置连接注册中心相关信息。
- address: zookeeper://192.168.25.128:2181
- protocol: #协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
- name: dubbo
- port:
- scan:
- base-packages: com.frost.service.impl
- version: 1.0.
- # Spring 配置
- spring:
- application:
- name: student-service
- datasource:
- # mysql
- driver-class-name: com.mysql.jdbc.Driver
- url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
- username: root
- password: root
- # mybatis 配置
- mybatis:
- # 映射文件
- mapper-locations: classpath:mapper/*.xml
- # 实体娄
- type-aliases-package: com.frost.entity
- configuration:
- # 自动开启大小写转换
- map-underscore-to-camel-case: true
- # 分页信息
- pagehelper:
- supportMethodsArguments: true
- reasonable: true
- helperDialect: mysql
- params: count=countSql
下面是客户端的pom文件和yml文件:
- <dependency>
- <groupId>com.frost</groupId>
- <artifactId>student_entity</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>com.frost</groupId>
- <artifactId>student_api</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>com.frost</groupId>
- <artifactId>student_common</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <!--分页插件-->
- <!--<dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper-spring-boot-starter</artifactId>
- <version>1.2.</version>
- </dependency>-->
- <!--Spring boot 和 dubbo 结和-->
- <dependency>
- <groupId>com.alibaba.boot</groupId>
- <artifactId>dubbo-spring-boot-starter</artifactId>
- <version>0.2.</version>
- </dependency>
- <!--Zookeeper 开源客户端-->
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <version>4.0.</version>
- </dependency>
- <!--zookeeper-->
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- <version>3.4.</version>
- </dependency>
(前三个也是本项目的依赖)
yml文件:
- server:
- port:
- # Spring 配置
- spring:
- application:
- name: student-client
- # dubbo 配置
- dubbo:
- application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
- name: student-client
- registry: #注册中心配置,用于配置连接注册中心相关信息。
- address: zookeeper://192.168.25.128:2181
- protocol: #协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
- name: dubbo
- port:
- version: 1.0.
下面是数据访问层的pom依赖:
- <dependency>
- <groupId>com.frost</groupId>
- <artifactId>student_entity</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <!--mysql-->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- <!--分页插件-->
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper-spring-boot-starter</artifactId>
- <version>1.2.</version>
- </dependency>
- <!--mybatis-->
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>1.3.</version>
- </dependency>
- <!--德鲁依数据库-->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid</artifactId>
- <version>1.1.</version>
- </dependency>
- <!--日志-->
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.</version>
- </dependency>
代码生成器的插件:
- <build>
- <plugins>
- <!--逆向工程-->
- <plugin>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-maven-plugin</artifactId>
- <version>1.3.</version>
- <configuration>
- <verbose>true</verbose>
- <overwrite>false</overwrite>
- </configuration>
- <dependencies>
- <!--mysql-->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.</version>
- </dependency>
- <!--oracle-->
- <!--<dependency>
- <groupId>cn.easyproject</groupId>
- <artifactId>ojdbc6</artifactId>
- <version>12.1.0.2.</version>
- </dependency>-->
- </dependencies>
- </plugin>
- </plugins>
- </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的更多相关文章
- Spring Boot 项目学习 (二) MySql + MyBatis 注解 + 分页控件 配置
0 引言 本文主要在Spring Boot 基础项目的基础上,添加 Mysql .MyBatis(注解方式)与 分页控件 的配置,用于协助完成数据库操作. 1 创建数据表 这个过程就暂时省略了. 2 ...
- Spring Boot入门(六):使用MyBatis访问MySql数据库(注解方式)
本系列博客记录自己学习Spring Boot的历程,如帮助到你,不胜荣幸,如有错误,欢迎指正! 本篇博客我们讲解下在Spring Boot中使用MyBatis访问MySql数据库的简单用法. 1.前期 ...
- Spring Boot(六):如何使用mybatis
Spring Boot(六):如何使用mybatis orm框架的本质是简化编程中操作数据库的编码,发展到现在基本上就剩两家了,一个是宣称可以不用写一句SQL的hibernate,一个是可以灵活调试动 ...
- Spring Boot (七): Mybatis极简配置
Spring Boot (七): Mybatis极简配置 1. 前言 ORM 框架的目的是简化编程中的数据库操作,经过这么多年的发展,基本上活到现在的就剩下两家了,一个是宣称可以不用写 SQL 的 H ...
- Spring Boot (八): Mybatis 增强工具 MyBatis-Plus
1. 简介 在上一篇文章<Spring Boot (七): Mybatis极简配置> 中我们介绍了在 Spring Boot 中 Mybatis 的基础使用方式,其中有一部分美中不足的是 ...
- Spring Boot 2.X(五):MyBatis 多数据源配置
前言 MyBatis 多数据源配置,最近在项目建设中,需要在原有系统上扩展一个新的业务模块,特意将数据库分库,以便减少复杂度.本文直接以简单的代码示例,如何对 MyBatis 多数据源配置. 准备 创 ...
- Spring Boot 整合 Dubbo和Zookeeper
Spring Boot 整合 Dubbo和Zookeeper Spring Boot 整合 Dubbo和Zookeeper 环境介绍 Zookeeper 安装 启动 Dubbo admin 搭建 创建 ...
- Spring Boot整合Dubbo框架demo
Dubbo框架原理见之前的博文:http://www.cnblogs.com/umgsai/p/5836925.html 首先启动zookeeper Server端 Pom配置如下 <?xml ...
- Spring Boot和Dubbo整合
provider端 POM依赖 <dependencies> <dependency> <groupId>org.springframework.boot</ ...
随机推荐
- 2.Shell脚本中的set指令,比如set -x 和 set -e
set参数介绍 set指令能设置所使用shell的执行方式,可依照不同的需求来做设置 -a 标示已修改的变量,以供输出至环境变量. -b 使被中止的后台程序立刻回报执行状态. -C 转向所产生的文件无 ...
- 在Go1.11.1中使用go module管理依赖
今天试验了一下go的版本管理Go moule,只是安装了下,由于目前还没有进行大的项目开发,暂时没有碰到坑. 使用了模块后,可以不用在GOPATH中再建立src目录了,直接在GOPATH中就行 另外, ...
- 搞Jedis案例出现问题,有大佬帮我看看怎么解决吗?先感谢大佬点进来看了---Day31
今天学了Jedis的相关内容,然后做了一个案例,但是出现了错误,然后我百度了一晚上没有解决,想到看看发个博客能不能有大佬帮我看一下问题出现在哪里,百度了一晚上有点懵逼.求大佬帮我解决,在这小弟我先万分 ...
- 0 != null 为什么报指针?
大家好,这是我第一次写博客,来分享我平时工作中遇到的问题及平时学习的技术,如果有写的不好或者不对的地方还望大家能够指出和包涵. 那么接下来就开始说下我工作中遇到的这个问题,我写了一个test,如下: ...
- C# 构造基础返回值类型-BaseResponse
学无止境,精益求精 十年河东,十年河西,莫欺少年穷 用于基础返回值类型,如下: using System; using System.Collections.Generic; using System ...
- MySQL语言分类——DDL
DDL的全称Data Definition Language,即数据定义语言 DDL的语法有:create.alter.drop.rename.truncate.对此做一个详细的解释: create ...
- springMVC对RESTful的支持
1:后台controller方法编写 @RequestMapping("/itemsLook/{id}") public ItemsCustom itemsLook(@PathVa ...
- 监控微信小程序中的慢HTTP请求
摘要: 请求时间太长,影响用户体验,使用 Fundebug 监控慢请求. Fundebug 的微信小程序监控插件在 0.5.0 版本已经支持监控 HTTP 请求错误,在小程序中通过wx.request ...
- Android 自定义ListView动态加载数据
我们都知道网络取数据是耗时操作,如果我们一次性请求所有数据,假如数据量不多那还可以接受,但是如果数据量特别多,那么带来的后果就是用户的愤怒(用户是很没有耐心的),所以这时候我们就需要动态的加载数据,分 ...
- 基于Spring Boot的注解驱动式公众号极速开发框架FastBootWeixin
本框架基于Spring Boot实现,使用注解完成快速开发,可以快速的完成一个微信公众号,重新定义公众号开发. 在使用本框架前建议对微信公众号开发文档有所了解,不过在不了解公众号文档的情况下使用本框架 ...