Dubbo 简单例子搭建遇到的坑

环境:
Dubble版本:2.7.0-SNAPSHOT
Netty版本:4

做一个最简单的Dubbo+Zookeeper Demo,Follow的是Apache Dubbo的官方例子

搭建编写好Provider和Consumer的类和配置文件后,启动报了以下错误。

Provider启动:

Exception in thread "main" org.apache.dubbo.rpc.RpcException: Unsupported server type: netty, url: dubbo://192.168.1.101:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.1.101&bind.port=20880&channel.readonly.sent=true&dubbo=2.0.2&generic=false&heartbeat=60000&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=12144&qos.port=22222&side=provider×tamp=1536248469908
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:301)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.openServer(DubboProtocol.java:283)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.export(DubboProtocol.java:267)
    at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:57)
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:100)
    at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)
    at org.apache.dubbo.registry.integration.RegistryProtocol.doLocalExport(RegistryProtocol.java:170)
    at org.apache.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:133)
    at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:55)
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:98)
    at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)
    at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:513)
    at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:358)
    at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:317)
    at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:216)
    at org.apache.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:123)
    at org.apache.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:49)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
    at org.apache.dubbo.demo.provider.Provider.main(Provider.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Consumer启动:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': FactoryBean threw exception on object creation; nested exception is org.apache.dubbo.rpc.RpcException: Unsupported client type: netty, supported client type is netty4
    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.consumer.Consumer.main(Consumer.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.apache.dubbo.rpc.RpcException: Unsupported client type: netty, supported client type is netty4
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.initClient(DubboProtocol.java:429)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.getSharedClient(DubboProtocol.java:405)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.getClients(DubboProtocol.java:376)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.refer(DubboProtocol.java:358)
    at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:67)
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:108)
    at org.apache.dubbo.rpc.Protocol$Adaptive.refer(Protocol$Adaptive.java)
    at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:397)
    at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:336)
    at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:165)
    at org.apache.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:66)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:170)
    ... 11 more

解决方案:
搜了好多居然都没有相关的信息,最后尝试了好几次,发现有这样的配置:
服务端:

<dubbo:provider server="netty4"/>

客户端:

<dubbo:consumer client="netty4" />

分别加入到Provider和Consumer的配置文件中就可解决上述问题!

你可能感兴趣的:(Dubbo,ZooKeeper)