Dubbo的IllegalArgumentException问题的解决

异常信息

一次项目启动失败的异常信息。

**********  省略前面的堆栈信息  ***********

Caused by: java.lang.IllegalArgumentException: @Service interfaceClass() or interfaceName() or interface class must be present!
		at org.springframework.util.Assert.notNull(Assert.java:193)
		at com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor.resolveServiceInterfaceClass(ServiceAnnotationBeanPostProcessor.java:344)
		at com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor.registerServiceBean(ServiceAnnotationBeanPostProcessor.java:251)
		at com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor.registerServiceBeans(ServiceAnnotationBeanPostProcessor.java:143)
		at com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor.postProcessBeanDefinitionRegistry(ServiceAnnotationBeanPostProcessor.java:104)
		at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271)
		at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:121)
		at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:692)
		at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530)
		at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
		at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
		at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
		at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
		at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157)
		at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137)
		at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
		at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
		at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
		at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
		... 44 more

异常信息: @Service interfaceClass() or interfaceName() or interface class must be present!
说的是dobbo提供的服务的类必须实现接口。但是下面的堆栈异常中有没有打印出来有问题的异常的类的信息, 最后还是我一个个检查dubbo服务发现问题。

问题原因:

dubbo提供服务的类必须直接实现接口, 间接继承实现接口不行

重现问题

接口

public interface TestService {

    String  test();
}

spring容器中实现类

import com.souche.intention.dubbo.service.TestService;
import org.springframework.stereotype.Component;

@Component
public class TestServiceImpl implements TestService {
    @Override
    public String test() {
        return "test";
    }
}

提供的dubbo服务

@com.alibaba.dubbo.config.annotation.Service
public class DubboTestService extends TestServiceImpl {
}

启动服务后果然报了同样的错误。

因为我图方便, 直接集成了spring中的bean类,然后来发布dubbo服务,这样我可以共用业务代码,所以导致了这个问题

解决办法

将dubbo服务类改成下面这样既集成业务类, 也实现对应接口就可以了

@com.alibaba.dubbo.config.annotation.Service
public class DubboTestService extends TestServiceImpl  implements TestService{
}

改好后启动项目. 启动后在注册中心找到了注册的服务TestService。 问题解决

思考

java中类可以继承多个接口, 如果dubbo服务的类直接继承了多个接口,
是否会每个接口的方法都会注册。 经过验证确实如此

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值