代码的链接地址: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文件里面配置了:

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

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

最新文章

  1. 【干货分享】流程DEMO-采购预算编制
  2. 2016 daily
  3. nginx配置反向代理解决前后端分离跨域问题
  4. bzoj 2659: [Beijing wc2012]算不出的算式
  5. 好用的PHP分页类
  6. CentOS安装zookeeper
  7. ruby中实例变量、类变量等等的区别和联系
  8. JSF 2 textbox example
  9. python3-day6(模块)
  10. WAMP多站点配置,更改服务器端口
  11. springboot 共享session
  12. arcgis10.2 sde配置
  13. JSTL 之 &lt;c:out&gt;
  14. j2me必备之网络开发数据处理
  15. 20170728xlVBA改转置一例
  16. 浅谈Java中的Hashmap
  17. codevs1839洞穴勘测
  18. dubbo服务引用与集群容错
  19. python----------闭包 、装饰器
  20. Verilog笔记.3.有限状态机

热门文章

  1. LearnOpenGL笔记(3)着色器
  2. salesforce零基础学习(九十四)classic下pagelayout引入的vf page弹出内容更新此page layout
  3. ELK——Elasticsearch 搭建集群经验
  4. 【转】PHP利用Apache、Nginx的特性实现免杀Webshell
  5. 金蝶BOS元模型分析
  6. android studio学习---签名打包的两种方式
  7. 七、Docker启动tocmat 8
  8. python实现生产者消费者模型
  9. 关于交叉熵损失函数Cross Entropy Loss
  10. 201871010108-高文利《面向对象程序设计(java)》第二周学习总结