首页>代码>SpringBoot2整合Apache Zookeeper集群管理、负载均衡功能代码>/zookeeper-demo1/src/main/java/com/test/ZookeeperDemo1Application.java
package com.test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import com.test.distributed.ImWorker; import com.test.distributed.PeerManager; /** * zookeeper集群测试 * @author 程就人生 * @date 2020年1月13日 */ @SpringBootApplication public class ZookeeperDemo1Application implements CommandLineRunner{ @Value("${server.port}") private int port; public static void main(String[] args) { //获取application的上下文 SpringApplication.run(ZookeeperDemo1Application.class, args); } /** * 项目启动后,将节点加入到zookeeper,保证一个服务器一个节点 */ @Override public void run(String... args) throws Exception { //组装节点信息 ImWorker.getInst().setLocalNode("localhost", port); //节点初始化 ImWorker.getInst().init(); //启动节点的管理,节点之间的通信 PeerManager.getInst().init(); } }


xianyu091012 LV5
2024年11月18日
fellowfun LV12
2023年9月1日
心如止水 LV17
2023年8月15日
yzshabzbbdvw LV4
2023年6月3日
lironggang LV38
2023年3月28日
zxc131313 LV12
2023年2月2日
bibibi234 LV1
2022年12月5日
xiaoyuer2 LV8
2022年11月20日
Hachi6 LV13
2022年9月19日
别胡思乱想啦
2022年6月18日
暂无贡献等级