xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--1.服务提供方在zookeeper中的“别名”-->
<dubbo:application name="dubbo-server"/>
<!--2.注册中心的地址-->
<dubbo:registry address="zookeeper://192.168.233.128:2181"/>
<!--3.扫描类(将什么包下的类作为服务提供类)-->
<dubbo:annotation package="service.impl"/>
</beans>
实现类
import com.alibaba.dubbo.config.annotation.Service;
import service.HelloService;
@Service
public class HelloServiceImpl implements HelloService {
@Override
public String sayHello(String name) {
return "Hello," + name + "!!!";
}
}
报错信息
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloServiceImpl' defined in file [D:\Workspace\zookeeper_code\dubbo-server\target\classes\service\impl\helloServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Failed to register dubbo://192.168.233.1:20880/service.HelloService?anyhost=true&application=dubbo-server&dubbo=2.5.7&generic=false&interface=service.HelloService&methods=sayHello&pid=3952&side=provider×tamp=1637743546439 to registry 192.168.233.128:2181, cause: Failed to register dubbo://192.168.233.1:20880/service.HelloService?anyhost=true&application=dubbo-server&dubbo=2.5.7&generic=false&interface=service.HelloService&methods=sayHello&pid=3952&side=provider×tamp=1637743546439 to zookeeper zookeeper://192.168.233.128:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-server&dubbo=2.5.7&interface=com.alibaba.dubbo.registry.RegistryService&pid=3952×tamp=1637743546422, cause: Zookeeper is not connected yet!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:587)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
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.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Failed to register dubbo://192.168.233.1:20880/service.HelloService?anyhost=true&application=dubbo-server&dubbo=2.5.7&generic=false&interface=service.HelloService&methods=sayHello&pid=3952&side=provider×tamp=1637743546439 to registry 192.168.233.128:2181, cause: Failed to register dubbo://192.168.233.1:20880/service.HelloService?anyhost=true&application=dubbo-server&dubbo=2.5.7&generic=false&interface=service.HelloService&methods=sayHello&pid=3952&side=provider×tamp=1637743546439 to zookeeper zookeeper://192.168.233.128:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-server&dubbo=2.5.7&interface=com.alibaba.dubbo.registry.RegistryService&pid=3952×tamp=1637743546422, cause: Zookeeper is not connected yet!
at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:149)
at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:120)
at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:54)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:92)
at com.alibaba.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:499)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:351)
at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:312)
at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:211)
at com.alibaba.dubbo.config.spring.AnnotationBean.postProcessAfterInitialization(AnnotationBean.java:191)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:437)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579)
... 20 more
Caused by: com.alibaba.dubbo.rpc.RpcException: Failed to register dubbo://192.168.233.1:20880/service.HelloService?anyhost=true&application=dubbo-server&dubbo=2.5.7&generic=false&interface=service.HelloService&methods=sayHello&pid=3952&side=provider×tamp=1637743546439 to zookeeper zookeeper://192.168.233.128:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-server&dubbo=2.5.7&interface=com.alibaba.dubbo.registry.RegistryService&pid=3952×tamp=1637743546422, cause: Zookeeper is not connected yet!
at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:112)
at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:136)
... 32 more
Caused by: java.lang.IllegalStateException: Zookeeper is not connected yet!
at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkClientWrapper.createPersistent(ZkClientWrapper.java:82)
at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.createPersistent(ZkclientZookeeperClient.java:45)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:47)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:41)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:41)
at com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:41)
at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:110)
... 33 more
有没有人可以解答下