Apache Dubbo的demo报错Error creating bean with name 'demoService': FactoryBean thre

scau-codeman 2019-05-23 09:51:52
最近刚刚学习apache dubbo,看了下官方文档,服务提供者注册服务成功,但是消费者调用服务失败抛异常,
异常堆栈信息如下:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': FactoryBean threw exception on object creation; nested exception is java.lang.UnsupportedOperationException
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:177)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1640)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
at org.apache.dubbo.demo.init.Consumer.main(Consumer.java:13)
Caused by: java.lang.UnsupportedOperationException
at java.util.concurrent.CopyOnWriteArrayList$COWIterator.set(CopyOnWriteArrayList.java:1185)
at java.util.Collections.sort(Collections.java:170)
at org.apache.dubbo.rpc.cluster.RouterChain.sort(RouterChain.java:87)
at org.apache.dubbo.rpc.cluster.RouterChain.initWithRouters(RouterChain.java:67)
at org.apache.dubbo.rpc.cluster.RouterChain.<init>(RouterChain.java:57)
at org.apache.dubbo.rpc.cluster.RouterChain.buildChain(RouterChain.java:46)
at org.apache.dubbo.registry.integration.RegistryDirectory.buildRouterChain(RegistryDirectory.java:622)
at org.apache.dubbo.registry.integration.RegistryProtocol.doRefer(RegistryProtocol.java:385)
at org.apache.dubbo.registry.integration.RegistryProtocol.refer(RegistryProtocol.java:367)
at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:114)
at org.apache.dubbo.qos.protocol.QosProtocolWrapper.refer(QosProtocolWrapper.java:70)
at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:65)
at org.apache.dubbo.rpc.Protocol$Adaptive.refer(Protocol$Adaptive.java)
at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:366)
at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:305)
at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:231)
at org.apache.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:71)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:170)
... 6 more


消费者的代码如下:

package org.apache.dubbo.demo.init;

import org.apache.dubbo.demo.DemoService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Consumer {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {
"classpath*:META-INF/spring/spring-config.xml"
});
context.start();
System.out.println("[consumer] 服务已经启动");
DemoService demoService = (DemoService) context.getBean("demoService");
String hello = demoService.sayHello("world");
System.out.println(hello);
System.in.read();
}
}


消费者服务配置如下:

<?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://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

<dubbo:application name="consumer-of-helloworld-app"/>

<!--使用 zookeeper 注册中心暴露服务,这里使用不能用client="zkclient"否则会报错,详细原因见:
https://github.com/apache/incubator-dubbo/issues/4084
-->
<dubbo:registry address="zookeeper://127.0.0.1:2181" client="curator" />

<!-- 用dubbo协议在20880端口暴露服务 -->
<!-- dubbo:protocol name="dubbo" port="20880" /-->

<dubbo:reference id="demoService" interface="org.apache.dubbo.demo.DemoService"/>
</beans>


提供者服务注册时正常的,如下图所示:


请大神指点,我是哪里出现了问题,导致调用服务抛这个异常

...全文
647 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
南朝喧嚣 2019-05-25
  • 打赏
  • 举报
回复
你消费者没配xml吗
scau-codeman 2019-05-24
  • 打赏
  • 举报
回复
我用的是apache dubbo2.7.1,在官方github上提问过说是开发者说是apache dubbo的bug,会在2.7.2版本中修复,我用了alibaba dubbo 2.6.6版本是可以正常跑的!
axzzy 2019-05-24
  • 打赏
  • 举报
回复
好吧,可以不用看了,xml完全不一样,找别的方面问题吧
axzzy 2019-05-24
  • 打赏
  • 举报
回复
<dubbo:reference id="demoService" interface="org.apache.dubbo.demo.DemoService"/> 把接口地址改为 org.apache.dubbo.demo.init试一下? 我用springboot写配置文件扫描的是消费者所在的包,不知道xml对不对
ninuxGithub 2019-05-24
  • 打赏
  • 举报
回复
可以参考https://github.com/ninuxGithub/dubbo-study 感觉是的xml写的有问题

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧