需要在Linux虚拟机上搭建zookeeper协议和dubbo注册中心
验证是否搭建成功:查看端口是否被监听
2.父子工程目录结构截图 3.创建SpringBoot父子模块工程 3.1父项目pom.xmlpom
打包成pom文件
3.2提供者子模块SpringBootInterface的pom.xml空
3.3提供者子模块SpringBootInterfaceImple的pom.xml4.提供者子模块Spring工程服务类创建 4.1SpringBootInterface类org.springframework.boot spring-boot-startercom.alibaba.boot dubbo-spring-boot-starter0.2.0 org.springframework.boot spring-boot-starter-testcom.openlab SpringBootInterface0.0.1-SNAPSHOT org.springframework.boot spring-boot-maven-plugin
public interface SpringBootService {
public String helloSpringBootDubbo(String name);
}
4.2SpringBootInterfaceImpl类
@Service
public class SpringBootServiceImpl01 implements SpringBootService {
@Override
public String helloSpringBootDubbo(String name) {
return "欢迎"+name+"学习SpringBoot整合ZooKeeper!!!";
}
}
4.3SpringBootInterfaceImpl的application.yml配置
dubbo:
registry:
protocol: zookeeper #注册协议
address: 192.168.188.128:2181 #注册ip端口地址
protocol: #配置dubbo的应用
port: 20882 #配置进行数据通信的端口
name: dubbo #配置应用名称
application:
name: dubbo-springboot-example #配置应用程序的name,一个式列
qos-enable: true
scan:
basePackages: com.openlab.service #扫码依赖子模块的服务的包
5.Dubbo监控中心
输入http://192.168.188.128:8080/ :虚拟机的ip端口
5.1未发布SpringBootInterfaceImpl,未启动SpringBoot容器: 5.2 发布SpringBootInterfaceImpl服务,启动SpringBoot容器:SpringApplication.run(ApplicationDubboSpringBoot.class);6.创建消费者子模块MySpringBootDubboConsumer的SpringMVC工程 6.1pom.xml
org.springframework.boot
spring-boot-starter-test
org.springframework.boot
spring-boot-starter-web
com.alibaba.boot
dubbo-spring-boot-starter
0.2.0
com.openlab
SpringBootInterface
0.0.1-SNAPSHOT
6.2application.yml
dubbo:
registry:
protocol: zookeeper #注册协议
address: 192.168.188.128:2181 #注册ip端口地址
protocol: #配置dubbo的应用
name: dubbo #配置应用名称
application:
name: MySpringBootDubboConsumer #配置应用程序的name,也就是消费者子模块一个式列名字
qos-enable: false #是否开启质量服务器
server:
port: 8081 #配置web工程端口
6.3controller
@RestController
public class HelloController {
//远程调用注入接口
@Reference
SpringBootService springBootService;
@RequestMapping("/hello")
public String helloSpringBoot(String name){
return springBootService.helloSpringBootDubbo(name);
}
}
6.4启动消费者子模块MySpringBootDubboConsumer,查看dubbo监控中心
SpringApplication.run(ApplicationSpringBootDubbuo.class);6.5路径测试 http://localhost:8081/hello?name=张三 7.Dubbo监控中心 8.总结
将ssm工程,划分为子模块形式,通过服务发布到监控中心,远程调用子模块服务接口,实现子模块服务之间的独立性。



