spring-boot整合dubbo,调用方启动报错

新手初学Dubbo,在整合Spring-boot做Demo时候,出现这样的问题。
服务提供者可以正常启动,调用方启动失败。多方尝试不得其解,无法解决。往过来人给指出问题所在。
下面放出代码

报错内容
2018-08-05 19:02:26.974  INFO 10060 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
Disconnected from the target VM, address: '127.0.0.1:1956', transport: 'socket'
2018-08-05 19:02:27.052 ERROR 10060 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field helloService in cn.mrthree.dubbo.HelloController required a bean of type 'cn.mrthree.dubbo.HelloService' that could not be found.


Action:

Consider defining a bean of type 'cn.mrthree.dubbo.HelloService' in your configuration.
提供方ServiceImpl
import org.springframework.stereotype.Service;
@Service("helloService")
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHello(String name) {
        return "Hello " + (name == null ? "World" : name);
    }
}
提供方配置
srping:
  dubbo:
    application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
      name: hello-service
    registry: #注册中心配置,用于配置连接注册中心相关信息。
      address: zookeeper://192.168.1.102:2181
    protocol:  #协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
      name: dubbo
      port: 20880
    service:
      interface: cn.mrthree.dubbo.HelloService
      ref: helloService
server:
  port: 8880
调用方Controller
package cn.mrthree.dubbo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
    @Autowired
    private HelloService helloService;
    @GetMapping("hello")
    public String hello(@RequestParam(value="name", required = false) String name){
        return helloService.sayHello(name);
    }
}
调用方配置
srping:
  dubbo:
    application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
      name: hello-consumer
    registry: #注册中心配置,用于配置连接注册中心相关信息。
      address: zookeeper://192.168.1.102:2181
    base-package: cn.mrthree.dubbo
    reference:
      id: helloService
      interface: cn.mrthree.dubbo.HelloService
server:
  port: 8881
  servlet:
    context-path: /dubbo-consumer
阅读 8k
1 个回答

报错提示的很清楚了

Consider defining a bean of type 'cn.mrthree.dubbo.HelloService' in your configuration.

个人认为是没有注入成功 可能是主程序配置未扫描到注解? 可以考虑使用dubbo的@Service注解和spring的注解结合 springboot本就是为了简化配置 为什么还用那么多配置呢?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题