Dubbo Invoke命令的一个坑 (服务入参含有枚举类型) enum

如果在Dubbo命令行中使用Invoke命令,入参含有枚举类型的时候:

UserResult smsSending(String key, Map context, BizCodeEnum bizCodeEnum);
 
  
dubbo > invoke UserActionDetailsService.smsSending("MerchantReleaseActivityComponent",{},"XXXX_PC")

No such method smsSending in service UserActionDetailsService
dubbo> invoke UserActionDetailsService.smsSending("MerchantReleaseActivityComponent",{},{"bizCodeEnum":"XXXX_PC"});

Invalid parameters, format: service.method(args)
dubbo > invoke UserActionDetailsService.smsSending("MerchantReleaseActivityComponent",
{},{"bizCodeEnum":"XXXX_PC","class":"com.xxxx.common.constant.BizCodeEnum"})

Failed to invoke method smsSending, cause: java.lang.IllegalArgumentException: Cannot reflectively create enum objects
java.lang.IllegalArgumentException: Cannot reflectively create enum objects
        at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
        at com.alibaba.dubbo.common.utils.PojoUtils.newInstance(PojoUtils.java:530)
        at com.alibaba.dubbo.common.utils.PojoUtils.realize0(PojoUtils.java:439)
        at com.alibaba.dubbo.common.utils.PojoUtils.realize(PojoUtils.java:199)
        at com.alibaba.dubbo.common.utils.PojoUtils.realize(PojoUtils.java:88)
        at com.alibaba.dubbo.rpc.protocol.dubbo.telnet.InvokeTelnetHandler.telnet(InvokeTelnetHandler.java:139)
        at com.alibaba.dubbo.remoting.telnet.support.TelnetHandlerAdapter.telnet(TelnetHandlerAdapter.java:54)
        at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:183)
        at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)
        at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:81)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

经过无穷无尽的尝试之后,N遍的百度,经一位高人指点,决定分析源码

dubbo 的invoke 源码:  InvokeTelnetHandler

找到了

Dubbo Invoke命令的一个坑 (服务入参含有枚举类型) enum_第1张图片

跟踪源码到 :PojoUtils

找到了

Dubbo Invoke命令的一个坑 (服务入参含有枚举类型) enum_第2张图片

恍然大悟啊

dubbo >  invoke UserActionDetailsService.smsSending("MerchantReleaseActivityComponent",
{},{"name":"XXXX_PC","class":"com.xxxx.common.constant.BizCodeEnum"})  


{"code":10000,"data":true,"extraMap":{},"message":"","success":true}
elapsed: 84 ms.

 

你可能感兴趣的:(java,dubbo)