Dubbo oninvoke报错 博客分类: Dubbo Dubbo
程序员文章站
2024-02-12 23:16:16
...
<!-- 方法存在缺陷:如果存在多个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);
}
<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);
}
推荐阅读
-
Dubbo报错:no provider available for the service
-
集成Nacos1.2.1和Dubbo2.7.6 消费者报错No provider available for the service xxx
-
Dubbo client 启动报错:No provider available for the service use dubbo version 2.5.3
-
Dubbo服务重启后不停报错[DUBBO] disconected from 问题原因解析
-
dubbo启动消费者报错:No provider available for the service。。null
-
Unexpected exception in the selector loop., dubbo version: xxx, current host: 127.0.0.1 报错
-
nacos dubbo 使用时遇到报错 No provider available from registry localhost:9090