为了账号安全,请及时绑定邮箱和手机立即绑定

dubbo应用自产自消报错?

dubbo应用自产自消报错?

潇潇雨雨 2019-05-25 14:04:59
背景:一个应用使用dubbo,自己提供的服务,自己去调。(不要问我干嘛通过dubbo去掉自己的服务)实践一:启动一个spring容器,加载dubbo容器,注册并使用dubbo服务。启动容器ClassPathXmlApplicationContextcontext=newClassPathXmlApplicationContext(newString[]{"classpath:provider.xml"});context.start();HiDubboFacadeo1=(HiDubboFacade)context.getBean("hiDubboFacade");Strings1=o1.hi("xxt11111");System.out.println(s1);System.out.println("reference1hashcode:"+o1.hashCode());HiDubboFacadeo2=(HiDubboFacade)context.getBean("helloDubbo");Strings2=o2.hi("xxt");System.out.println(s2);System.out.println("reference2hashcode:"+o2.hashCode());没有问题:ireceivedmsg:xxt11111reference1hashcode:352598575[2017-07-2016:27:59.659][main][INFO][c.a.dubbo.config.AbstractConfig]-[DUBBO]Usinginjvmservicecom.coder4j.job.facade.HiDubboFacade,dubboversion:2.5.3,currenthost:127.0.0.1[2017-07-2016:27:59.659][main][INFO][c.a.dubbo.config.AbstractConfig]-[DUBBO]Referdubboservicecom.coder4j.job.facade.HiDubboFacadefromurlinjvm://127.0.0.1/com.coder4j.job.facade.HiDubboFacade?application=app&dubbo=2.5.3&interface=com.coder4j.job.facade.HiDubboFacade&methods=hi&pid=11220&side=consumer×tamp=1500539279654,dubboversion:2.5.3,currenthost:127.0.0.1ireceivedmsg:xxtreferencehashcode:1873091796实践二:使用相同的配置,在web应用中启动,就拿不到helloDubbo,报错。Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'helloDubbo':FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisjava.lang.IllegalStateException:Failedtocheckthestatusoftheservicecom.coder4j.job.facade.HiDubboFacade.Noprovideravailablefortheservicecom.coder4j.job.facade.HiDubboFacadefromtheurlregistry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=app&cluster=available&dubbo=2.5.3&pid=13008&refer=application%3Dapp%26dubbo%3D2.5.3%26interface%3Dcom.coder4j.job.facade.HiDubboFacade%26methods%3Dtell%2Chello%26pid%3D13008%26revision%3D1.0.0%26side%3Dconsumer%26timestamp%3D1500532931746®istry=zookeeper×tamp=1500532931788totheconsumer192.168.23.144usedubboversion2.5.3atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)atorg.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1634)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)atorg.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)atcom.coder4j.job.integration.MyIntegration.setApplicationContext(MyIntegration.java:61)atorg.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:121)atorg.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)...20moreCausedby:java.lang.IllegalStateException:Failedtocheckthestatusoftheservicecom.coder4j.job.facade.HiDubboFacade.Noprovideravailablefortheservicecom.coder4j.job.facade.HiDubboFacadefromtheurlregistry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=app&cluster=available&dubbo=2.5.3&pid=13008&refer=application%3Dapp%26dubbo%3D2.5.3%26interface%3Dcom.coder4j.job.facade.HiDubboFacade%26methods%3Dtell%2Chello%26pid%3D13008%26revision%3D1.0.0%26side%3Dconsumer%26timestamp%3D1500532931746®istry=zookeeper×tamp=1500532931788totheconsumer192.168.23.144usedubboversion2.5.3atcom.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:420)atcom.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300)atcom.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138)atcom.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)...31more实践三:如果我单独启动一个springjava容器,将服务注册到zookeeper,再启动一个web应用是可以拿到java容器发布的服务的。请问,在web应用中,自己发布的服务,自己不能够消费嘛????
查看完整描述

2 回答

?
一只名叫tom的猫

TA贡献1906条经验 获得超3个赞

我只能说很有可能是springmvc和spring的容器问题,dubbo中的对象是在spring容器中的,springmvc可能拿不到
                            
查看完整回答
反对 回复 2019-05-25
  • 2 回答
  • 0 关注
  • 367 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信