修改办法
方法一:适用于xml配置dubbo的方案。
<dubbo:registry id="registry1" address="zookeeper://localhost:2181" timeout="25000"/>
或者
<dubbo:config-center timeout="25000"/>
方法二:适用于api配置dubbo的方案。
private static void startWithBootstrap() {
ServiceConfig<DemoServiceImpl> serviceServiceConfig = new ServiceConfig<>();
serviceServiceConfig.setInterface(DemoService.class);
serviceServiceConfig.setRef(new DemoServiceImpl());
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-one-api-provider"))
.registry(new RegistryConfig("zookeeper://localhost:2181?timeout=25000"))
.service(serviceServiceConfig)
.start()
.await();
}
private static void startWithExport() throws InterruptedException {
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
service.setRegistry(new RegistryConfig("zookeeper://localhost?timeout=25000"));
service.export();
System.out.println("dubbo service started");
new CountDownLatch(1).await();
}
方法三:适用于注解配置的。
@Configuration
@EnableDubbo(scanBasePackages = "com.rsw")
@PropertySource("classpath:/spring/dubbo_provider.properties")
static class ProviderConfiguration {
@Bean
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("zookeeper://localhost:2181");
return registryConfig;
}
}
另外一种情况就是zookeeper的版本问题了,可以在pom文件中移除内置的zookeeper,然后在手动添加合适版本的zookeeper依赖包了。