心血来潮想要搭建一下dubbo项目,对整个dubbo有更深的理解,搭建项目使用的idea是idea2020,使用springboot进行整合
先是在官方看了一下官方文档的pom配置,按照官方配置进行导包,
2.2.6.RELEASE
2.7.6
org.springframework.boot
spring-boot-dependencies
${spring-boot.version}
pom
import
org.apache.dubbo
dubbo-dependencies-bom
${dubbo.version}
pom
import
org.apache.dubbo
dubbo-spring-boot-starter
2.7.6
导入之后启动,发现这时会报java.lang.NoClassDefFoundError: org/apache/curator/framework/CuratorFrameworkFactory这个错误,
java.lang.NoClassDefFoundError: org/apache/curator/framework/CuratorFrameworkFactory
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.(CuratorZookeeperClient.java:66) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter.createZookeeperClient(CuratorZookeeperTransporter.java:26) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperTransporter.connect(AbstractZookeeperTransporter.java:70) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter$Adaptive.connect(ZookeeperTransporter$Adaptive.java) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfiguration.(ZookeeperDynamicConfiguration.java:70) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfigurationFactory.createDynamicConfiguration(ZookeeperDynamicConfigurationFactory.java:37) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory.lambda$getDynamicConfiguration$0(AbstractDynamicConfigurationFactory.java:39) ~[dubbo-2.7.6.jar:2.7.6]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_211]
at org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory.getDynamicConfiguration(AbstractDynamicConfigurationFactory.java:39) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.common.config.configcenter.DynamicConfiguration.getDynamicConfiguration(DynamicConfiguration.java:223) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.prepareEnvironment(DubboBootstrap.java:857) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.startConfigCenter(DubboBootstrap.java:603) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.useRegistryAsConfigCenterIfNecessary(DubboBootstrap.java:671) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.initialize(DubboBootstrap.java:509) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:740) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onContextRefreshedEvent(DubboBootstrapApplicationListener.java:59) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onApplicationContextEvent(DubboBootstrapApplicationListener.java:52) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.spring.context.OneTimeExecutionApplicationContextEventListener.onApplicationEvent(OneTimeExecutionApplicationContextEventListener.java:40) ~[dubbo-2.7.6.jar:2.7.6]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:897) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at com.lmm.userserviceprovider.UserServiceProviderApplication.main(UserServiceProviderApplication.java:11) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.6.RELEASE.jar:2.2.6.RELEASE]
Caused by: java.lang.ClassNotFoundException: org.apache.curator.framework.CuratorFrameworkFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_211]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_211]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_211]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_211]
... 38 common frames omitted
这个错误是因为没有导入zk客户端导致的问题,本来以为dubbo的starter里面已经包括了这个包,结果没有,于是便导入了curator包:
org.apache.curator
curator-framework
4.0.1
org.apache.curator
curator-recipes
4.0.1
你以为这样终于可以启动了吗?很可惜还是继续报错,这次报错是报了java.lang.IllegalStateException: Failed to register dubbo://127.0.0.1:20880
java.lang.IllegalStateException: Failed to register dubbo://127.0.0.1:20880/com.myflower.base.service.UserService?anyhost=true&application=user-service-provider&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=com.myflower.base.service.UserService&methods=getUserAddressList&pid=61622&release=2.7.6&revision=0.0.1-SNAPSHOT&side=provider×tamp=1590917836978 to registry 127.0.0.1:2181, cause: Failed to register dubbo://127.0.0.1:20880/com.myflower.base.service.UserService?anyhost=true&application=user-service-provider&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=com.myflower.base.service.UserService&methods=getUserAddressList&pid=61622&release=2.7.6&revision=0.0.1-SNAPSHOT&side=provider×tamp=1590917836978 to zookeeper zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=user-service-provider&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=61622&qos.enable=false&release=2.7.6×tamp=1590917836976, cause: KeeperErrorCode = Unimplemented for /dubbo/com.myflower.base.service.UserService/providers/dubbo%3A%2F%2F127.0.0.1%3A20880%2Fcom.myflower.base.service.UserService%3Fanyhost%3Dtrue%26application%3Duser-service-provider%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dcom.myflower.base.service.UserService%26methods%3DgetUserAddressList%26pid%3D61622%26release%3D2.7.6%26revision%3D0.0.1-SNAPSHOT%26side%3Dprovider%26timestamp%3D1590917836978
at org.apache.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:253) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.registry.ListenerRegistryWrapper.register(ListenerRegistryWrapper.java:57) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.registry.integration.RegistryProtocol.register(RegistryProtocol.java:173) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:207) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:151) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:60) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:64) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:492) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:325) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:300) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:206) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.lambda$exportServices$15(DubboBootstrap.java:917) ~[dubbo-2.7.6.jar:2.7.6]
at java.util.HashMap$Values.forEach(HashMap.java:981) ~[na:1.8.0_211]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.exportServices(DubboBootstrap.java:905) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:745) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onContextRefreshedEvent(DubboBootstrapApplicationListener.java:59) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onApplicationContextEvent(DubboBootstrapApplicationListener.java:52) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.config.spring.context.OneTimeExecutionApplicationContextEventListener.onApplicationEvent(OneTimeExecutionApplicationContextEventListener.java:40) ~[dubbo-2.7.6.jar:2.7.6]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:897) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at com.lmm.userserviceprovider.UserServiceProviderApplication.main(UserServiceProviderApplication.java:11) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.6.RELEASE.jar:2.2.6.RELEASE]
Caused by: org.apache.dubbo.rpc.RpcException: Failed to register dubbo://127.0.0.1:20880/com.myflower.base.service.UserService?anyhost=true&application=user-service-provider&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=com.myflower.base.service.UserService&methods=getUserAddressList&pid=61622&release=2.7.6&revision=0.0.1-SNAPSHOT&side=provider×tamp=1590917836978 to zookeeper zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=user-service-provider&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=61622&qos.enable=false&release=2.7.6×tamp=1590917836976, cause: KeeperErrorCode = Unimplemented for /dubbo/com.myflower.base.service.UserService/providers/dubbo%3A%2F%2F127.0.0.1%3A20880%2Fcom.myflower.base.service.UserService%3Fanyhost%3Dtrue%26application%3Duser-service-provider%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dcom.myflower.base.service.UserService%26methods%3DgetUserAddressList%26pid%3D61622%26release%3D2.7.6%26revision%3D0.0.1-SNAPSHOT%26side%3Dprovider%26timestamp%3D1590917836978
at org.apache.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:130) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:240) ~[dubbo-2.7.6.jar:2.7.6]
... 38 common frames omitted
Caused by: java.lang.IllegalStateException: KeeperErrorCode = Unimplemented for /dubbo/com.myflower.base.service.UserService/providers/dubbo%3A%2F%2F127.0.0.1%3A20880%2Fcom.myflower.base.service.UserService%3Fanyhost%3Dtrue%26application%3Duser-service-provider%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dcom.myflower.base.service.UserService%26methods%3DgetUserAddressList%26pid%3D61622%26release%3D2.7.6%26revision%3D0.0.1-SNAPSHOT%26side%3Dprovider%26timestamp%3D1590917836978
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createEphemeral(CuratorZookeeperClient.java:110) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.create(AbstractZookeeperClient.java:87) ~[dubbo-2.7.6.jar:2.7.6]
at org.apache.dubbo.registry.zookeeper.ZookeeperRegistry.doRegister(ZookeeperRegistry.java:128) ~[dubbo-2.7.6.jar:2.7.6]
... 39 common frames omitted
Caused by: org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /dubbo/com.myflower.base.service.UserService/providers/dubbo%3A%2F%2F127.0.0.1%3A20880%2Fcom.myflower.base.service.UserService%3Fanyhost%3Dtrue%26application%3Duser-service-provider%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dcom.myflower.base.service.UserService%26methods%3DgetUserAddressList%26pid%3D61622%26release%3D2.7.6%26revision%3D0.0.1-SNAPSHOT%26side%3Dprovider%26timestamp%3D1590917836978
at org.apache.zookeeper.KeeperException.create(KeeperException.java:103) ~[zookeeper-3.5.3-beta.jar:3.5.3-beta-8ce24f9e675cbefffb8f21a47e06b42864475a60]
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) ~[zookeeper-3.5.3-beta.jar:3.5.3-beta-8ce24f9e675cbefffb8f21a47e06b42864475a60]
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1525) ~[zookeeper-3.5.3-beta.jar:3.5.3-beta-8ce24f9e675cbefffb8f21a47e06b42864475a60]
at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1181) ~[curator-framework-4.0.1.jar:4.0.1]
at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1158) ~[curator-framework-4.0.1.jar:4.0.1]
at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:64) ~[curator-client-4.0.1.jar:na]
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:100) ~[curator-client-4.0.1.jar:na]
at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1155) ~[curator-framework-4.0.1.jar:4.0.1]
at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:605) ~[curator-framework-4.0.1.jar:4.0.1]
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:595) ~[curator-framework-4.0.1.jar:4.0.1]
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:573) ~[curator-framework-4.0.1.jar:4.0.1]
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:49) ~[curator-framework-4.0.1.jar:4.0.1]
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createEphemeral(CuratorZookeeperClient.java:101) ~[dubbo-2.7.6.jar:2.7.6]
... 41 common frames omitted
,dubbo无法注册到注册中心上,当时就想dubbo的注册中心使用的是Zookeeper,已经导入了zk的包了,为什么还不能注册上去,于是去搜了一下这方面的文章,终于找到了原因:服务端的zookeeper版本和客户端的zookeeper版本不一致导致的,然后我就看了一下本机的zk版本,我看是3.4.12版本,我想着这版本用3.3.0的zk包应该可以吧(我觉得不过分),想着这个版本也还行,就不用博客推荐的低版本的客户端,使用相对高一点的(谁也逃不过“真香定律”),结果还是太年轻了,依然报无法注册,于是我最终还是按照了搜到的文章(真香~),中规中矩的使用了2.12.0版本的zk客户端,
org.apache.curator
curator-framework
2.12.0
org.apache.curator
curator-recipes
2.12.0
终于项目启动起来了。真不容易哟~
附上最后zk问题的文章