0
votes

I configured dubbo, using the registry zookeeper, when I start the service, I get an error.

  1. I modified the timeout to 10000 and the error has not changed.
  2. I turned off the firewall in the virtual machine and the error has not changed.
  3. I checked the dubbo and zookeeper and they are all running.
###This is the code I configured for the dubbo service.###

<dubbo:application name="pinyougou-user-service" />
<dubbo:registry address="zookeeper://192.168.25.128:2181" />
<dubbo:annotation package="com.pinyougou.user.service.impl" />
###This is the configuration of the service###

package com.pinyougou.user.service.impl;
import com.alibaba.dubbo.config.annotation.Service;
@Service(interfaceName="com.pinyougou.user.service.UserService")
public class UserServiceImpl implements UserService {
...
}
###Zookeeper service starts normally###

JMX enabled by default
Using config: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
###The firewall is not turned on either.###
iptables: Firewall is not running.

Wrong content

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl' defined in file [D:\Java\JavaCode\pinyougou\pinyougou-itcast\pinyougou-parent\pinyougou-user-service\target\classes\com\pinyougou\user\service\impl\UserServiceImpl.class]: Initialization of bean failed; nested exception is org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 5000
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 5000
    at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:1223)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:155)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:129)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:125)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:92)
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.<init>(ZkclientZookeeperClient.java:26)
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperTransporter.connect(ZkclientZookeeperTransporter.java:10)
    at com.alibaba.dubbo.remoting.zookeeper.ZookeeperTransporter$Adpative.connect(ZookeeperTransporter$Adpative.java)
    at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.<init>(ZookeeperRegistry.java:69)
    at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistryFactory.createRegistry(ZookeeperRegistryFactory.java:37)
    at com.alibaba.dubbo.registry.support.AbstractRegistryFactory.getRegistry(AbstractRegistryFactory.java:94)
    at com.alibaba.dubbo.registry.RegistryFactory$Adpative.getRegistry(RegistryFactory$Adpative.java)
    at com.alibaba.dubbo.registry.integration.RegistryProtocol.getRegistry(RegistryProtocol.java:190)
    at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:109)
    at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:54)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:53)
    at com.alibaba.dubbo.rpc.Protocol$Adpative.export(Protocol$Adpative.java)
    at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:489)
    at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:285)
    at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:246)
    at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:145)
    at com.alibaba.dubbo.config.spring.AnnotationBean.postProcessAfterInitialization(AnnotationBean.java:202)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    ... 20 more
3

3 Answers

0
votes

The error is because the zookeeper connection is abnormal:

  1. check your registry address(ip, port)
  2. check zk-client and zk-server version.
0
votes

It should be the zookeeper connection problem, use below command to check:

ping 192.168.25.128

If zookeeper and dubbo service are at the same machine, you can use localhost or 127.0.0.1.

0
votes

it may really because of the timeout's config is too short. i resolved it by set this:

    spring:
      dubbo:
        application:
          logger: log4j
        protocol:
          name: dubbo
          port: 20881
        registry:
          timeout: 20000