前言
目前互联网公司,大部分项目都是基于分布式,一个项目被拆分成几个小项目,这些小项目会分别部署在不同的计算机上面,这个叫做微服务。当一台计算机的程序需要调用另一台计算机代码的时候,就涉及远程调用。此时dubbo就粉末登场了。
搭建工程
idea新建工程后,删除src文件夹,然后在gradle文件中输入
buildscript { repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } mavenCentral() } dependencies { classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.21.RELEASE' }}plugins { id 'java'}apply plugin: 'org.springframework.boot'apply plugin: 'war'group 'com.demoMuty'version '1.0-SNAPSHOT'sourceCompatibility = 1.8repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } mavenCentral()}dependencies { compile 'org.springframework.boot:spring-boot-starter-mail' compile 'org.springframework.boot:spring-boot-starter-thymeleaf' compile 'org.springframework.boot:spring-boot-starter-web' compile 'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.4' compile 'com.alibaba.boot:dubbo-spring-boot-starter:0.1.0' compile 'com.101tec:zkclient:0.10'// developmentOnly 'org.springframework.boot:spring-boot-devtools' runtime 'mysql:mysql-connector-java' compile("com.baomidou:mybatis-plus-boot-starter:3.1.0") compile("com.baomidou:mybatis-plus-generator:3.1.1") compileOnly 'org.projectlombok:lombok' testCompile 'org.springframework.boot:spring-boot-starter-test'}如图所示
boolean作为父工程,然后再见三个模块
booleanone作为父模块 booleanteo作为服务者模块 booleanthree作为消费者模块
添加dubbo.xml
然后在每个模块新建com.test包,在包下新建启动类
然后在每个模块的gradle文件中引入上面的依赖,然后在消费者模块和生产者模块的依赖中加入父模块依赖,如图
然后在booleantwo的生产者模块的resource资源文件中加入dubbo文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http:///blackdogss/HelloWorld.git以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。