`

Dubbo oninvoke报错

阅读更多
<!-- 方法存在缺陷:如果存在多个onreturn、onthrow的话,方法名不能相同,如果相同就会出现回调覆盖现象 -->
    <dubbo:reference id="userService" group="db" interface="com.patty.dubbo.api.service.UserService"
                     timeout="500" retries="0" mock="true" check="false">
        <dubbo:method name="findAllUsers" merger="myMerger" cache="lru" />
        <dubbo:method name="findUserById" async="false" onreturn="notifyImpl.onreturn" onthrow="notifyImpl.onthrow" />
        <dubbo:method name="asyncOnreturn" async="true" onreturn="asyncNotifyImpl.asyncOnreturn"/>
        <dubbo:method name="asyncOnthrow" async="true" onthrow="asyncNotifyImpl.asyncOnthrow"/>
        <dubbo:method name="asyncOninvoke" async="true" oninvoke="asyncNotifyImpl.asyncOninvoke"/>
    </dubbo:reference>

在配置文件中加上<dubbo:method name="asyncOninvoke" async="true" oninvoke="asyncNotifyImpl.asyncOninvoke"/>后系统报错无法正常运行。Spring提示找不到名称为“asyncNotifyImpl.asyncOninvoke”的bean。为什么onreturn和onthrow都可以呢?
原因是dubbo没有处理oninvoke属性。下面是dubbo2.8.4版本的处理。

} else if ("onreturn".equals(property)) {
                                    int index = value.lastIndexOf(".");
                                    String returnRef = value.substring(0, index);
                                    String returnMethod = value.substring(index + 1);
                                    reference = new RuntimeBeanReference(returnRef);
                                    beanDefinition.getPropertyValues().addPropertyValue("onreturnMethod", returnMethod);
                                } else if ("onthrow".equals(property)) {
                                    int index = value.lastIndexOf(".");
                                    String throwRef = value.substring(0, index);
                                    String throwMethod = value.substring(index + 1);
                                    reference = new RuntimeBeanReference(throwRef);
                                    beanDefinition.getPropertyValues().addPropertyValue("onthrowMethod", throwMethod);
                                } else {//在此没有处理oninvoke属性
                                    if ("ref".equals(property) && parserContext.getRegistry().containsBeanDefinition(value)) {
                                        BeanDefinition refBean = parserContext.getRegistry().getBeanDefinition(value);
                                        if (! refBean.isSingleton()) {
                                            throw new IllegalStateException("The exported service ref " + value + " must be singleton! Please set the " + value + " bean scope to singleton, eg: <bean id=\"" + value+ "\" scope=\"singleton\" ...>");
                                        }
                                    }
                                    reference = new RuntimeBeanReference(value);
                                }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics