赞
踩
1.在父工程pom.xml中声明dubbo依赖
<depencyManagement> <dependencies> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <!-- 注意:使用此EL表达式取版本号时 要在propertis标签中声明 <dubbo.version>X.X.X</dubbo.version> --> <version>${dubbo.version}</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-zookeeper</artifactId> <version>${dubbo.version}</version> </dependency> </dependencies> </depencyManagement>
2.在common工程中引入所需依赖 这里只引入了dubbo与zk
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-start-</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}<version>
<type>pom</type>
</dependency>
</dependencies>
3.在provider和consumer工程中引入common工程的依赖 (依赖传递)
<dependencies>
<dependency>
<groupId>com.xxx</groupId>
<artifactId>dubbo-common</artifactId>
</dependency>
</dependencies>
4.配置provider和consumer的yml/properties文件
consumer:
server:
port:8081 #Tomcat服务器端口号
dubbo:
application:#dubbo的应用名
name:consumer
registry:
address:zookeeper://LinuxIP地址:zookeeper端口号
provider:
server:
port:8080
dubbo:
application:
name:provider
registry:
address:zookeeper://LinuxIP地址:zookeeper端口号
timeout:6000 #连接超时时间
protocol:
port:20800 #端口号
name:dubbo #dubbo协议名
scan:
base-packages:com.xxx.serviceImpl
5.在Linux中启动zk:
进入zk的bin目录在bin目录中输入命令 ./zkServer.sh start
继续输入命令 ./zkServer.sh status 查看zk启动状态
出现Mode:standalone 即启动成功
注意:
1.提前配置好linux下zookeeper
2.必须关闭linux防火墙 命令:systemctl stop firewalld.server (CentOS 7)
6.启动provider和consumer的工程 最后访问路径中路径的端口号:
localhost:consumer中server.port的端口号(8081/8080…具体看自己需求)/controller中RequestMapping中的路径
例如:localhost:8080/login 可以访问controller中路径并没有出现404 500等状态码即启动成功!
Ps:如有不足还请补充
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。