1.新建普通maven工程

2.在父级pom中按需修改

3.删除父级src目录

4.创建公共模块common,里面只有service接口和实体类


5.构建微服务模块,provider



6.引用Zookeeper和Dubbo的依赖

在这个provider中修改pom文件坐标

  <dependencies>
<!--引入公共模块项目-->
<dependency>
<groupId>cn.kgc</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--这是微服dubbo的核心服务包-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!--这是zookeeper的服务操作包 但主要这里的版本最好和你的zookeeper版本一致-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--这里是zookeeper的zkCli的操作包 我们读写服务全靠这个包-->
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

7.在provider中写mapper和service的实现

8.在启动类上添加mapper扫描注解

9.在resources下建这两个文件,用于注册

9.1application.properties

修改需要的url参数和分页插件参数

server.port=9090

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/kgc
spring.datasource.username=root
spring.datasource.password=ok mybatis.type-aliases-package=cn.kgc.vo mybatis.mapper-locations=mapper/*.xml pagehelper.helper-dialect=mysql

9.2spring-provider.xml

根据需要修改用户服务接口中的参数,作用是将service的接口注入到Zookeeper中去

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="myprovider" /> <!-- 使用zookeeper注册中心暴露服务地址,我的zookeeper是架在本地的 -->
<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" timeout="60000"/> <!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" /> <!-- 用户服务接口 -->
<dubbo:service interface="cn.kgc.service.TableToOneService" ref="tableToOneService"/>
<bean id="tableToOneService" class="cn.kgc.service.TableToOneServiceImpl"/> <dubbo:service interface="cn.kgc.service.TableToManyService" ref="tableToManyService"/>
<bean id="tableToManyService" class="cn.kgc.service.TableToManyServiceImpl"/>
</beans>

10再修改启动项,添加导入资源注解

11再创建微服务模块,consumer



12.把provider中pom的坐标拷贝到consumer

13.把provider中的application文件拷贝到consumer,并按需修改(端口号等)

14.编写controller类和添加spring-consumer.xml

14.1spring-consumer.xml

按需修改service名

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:application name="dubbo-consumer"/>
<dubbo:registry check="false" address="zookeeper://127.0.0.1:2181"/>
<dubbo:reference interface="cn.kgc.service.TableToOneService" id="tableToOneService"/>
<dubbo:reference interface="cn.kgc.service.TableToManyService" id="tableToManyService"/>
</beans>

15再启动类上添加导入资源注解

全部代码写完

然后开启Zookeeper服务器,然后开启provider启动类,再开启consumer启动类,最后用postman检测接口是否通畅,根据错误信息修改代码..

整体流程

https://www.cnblogs.com/jsccc520/p/12006237.html

springBoot框架在idea中创建流程 同时存在一个项目中的更多相关文章

  1. Java归去来第4集:java实战之Eclipse中创建Maven类型的SSM项目

    一.前言 如果还不了解剧情,请返回第3集的剧情          Java归去来第3集:Eclipse中给动态模块升级 二.在Eclipse中创建Maven类型的SSM项目 2.1:SSM简介 SSM ...

  2. eclipse中创建多模块maven web项目

    本文讲述在eclipse中创建分模块maven web项目. 暂时将一个项目分为controller:service:dao以及父类模块四部分. 1.创建父类模块. 创建一个简单的maven proj ...

  3. 编写Java程序,使用ThreadLocal类,项目中创建账户类 Account,类中包括账户名称name、 ThreadLocal 类的引用变量amount,表示存款

    查看本章节 查看作业目录 需求说明: 某用户共有两张银行卡,账户名称相同,但卡号和余额不同.模拟用户使用这两张银行卡进行消费的过程,并打印出消费明细 实现思路: 项目中创建账户类 Account,类中 ...

  4. CI中的控制器中要用model中的方法,是统一写在构造器方法中,还是在每一个方法中分别写

    Q: CI中的控制器中要用model中的方法,是统一写在构造器方法中,还是在每一个方法中分别写 A: 建议统一写,CI框架会自动识别已经加载过的类,所以不用担心重复加载的问题 class C_User ...

  5. 如何在外网中访问自己在另一个局域网中的某个机器(SSH为例)

    UBUNTU 14.04 LTS 为例 如何在外网中访问自己在另一个局域网中的某个机器(SSH为例) 2013-05-01 16:02 2693人阅读 评论(0) 收藏 举报 情景描述: 计算机C1放 ...

  6. eclipse中将一个项目作为library导入另一个项目中

    1. github上搜索viewpagerIndicator: https://github.com/JakeWharton/ViewPagerIndicator2. 下载zip包,解压,eclips ...

  7. 解决tomcat下面部署多个项目log4j的日志输出会集中输出到一个项目中的问题

    在一次项目上线后,发现了一个奇怪的问题,经过对源码的阅读调试终于解决,具体经过是这样的: 问题描述:tomcat7下面部署多个项目,log4j的日志输出会集中输出到一个项目中,就算配置了日志文件的绝对 ...

  8. (转)最近一个项目中关于NGUI部分的总结(深度和drawCall)

    在自己最近的一个项目中,软件的界面部分使用了NGUI来进行制作.在制作过程中,遇到了一些问题,也获取了一些经验,总结下来,作为日后的积累. 1.NGUI图集的使用. 此次是第一个自己正儿八经的制作完整 ...

  9. 将一个文件中的内容,在另一个文件中生成. for line in f1, \n f2.write(line)

    将一个文件中的内容,在另一个文件中生成. 核心语句: for line in f1: f1中的所有一行 f2.write(line)                                  ...

随机推荐

  1. Python中dict的特点

    dict的第一个特点是查找速度快,无论dict有10个元素还是10万个元素,查找速度都一样.而list的查找速度随着元素增加而逐渐下降. 不过dict的查找速度快不是没有代价的,dict的缺点是占用内 ...

  2. PHP- 搜索插入位置

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 输入: [1,3,5,6], 5输出 ...

  3. vue 点击当前元素改变样式

    template  <ul>    <li v-for="(relation,index) in relations" v-bind:id="relat ...

  4. List Comprehension ()(一)

    >>> L = [1,2,3,4,5] >>> L = [x+10 for x in L] >>> L [11, 12, 13, 14, 15] ...

  5. Struts2增删改查(自己思路理解)

    1:查询所有: DAO层:把所有的信息都放到list集合中.然后返回. public List<Employee> getEmployees(){ return new ArrayList ...

  6. 深入研究CSS

    通常我们在学习CSS的时候,感觉很容易掌握,却常常在实际应用中碰到各式各样难以填补的“坑”,为避免大家受到同样的困惑与不解,本文详细讲解了CSS中优先级和Stacking Context等诸多高级特性 ...

  7. H5页面前后端通信 (3种方式简单介绍)

    1.ajax:短连接 2.websocket :长连接,双向的.   node搭建的websocket服务器,推送信息给客户端浏览器 :https://www.cnblogs.com/fps2tao/ ...

  8. QTP学习笔记---datatable应用

    DataTable应用1.定位数据行 DataTable.GetSheet() 2.获取当前行 GetCurrentRow3.获取指定行的值 getValueByRow = DataTable.Get ...

  9. 在IIS7以上导出所有应用程序池的方法批量域名绑定(网站绑定)

    在IIS7+上导出所有应用程序池的方法: %windir%/system32/inetsrv/appcmd list apppool /config /xml > c:/apppools.xml ...

  10. MySQL高级学习笔记(六):MySql锁机制

    文章目录 概述 定义 生活购物 锁的分类 从对数据操作的类型(读\写)分 从对数据操作的粒度分 三锁 表锁(偏读) 特点 案例分析 建表SQL 加读锁 加写锁 结论 如何分析表锁定 行锁(偏写) 特点 ...