鍍金池/ 問答/Java  網(wǎng)絡(luò)安全/ spring-boot整合dubbo,調(diào)用方啟動(dòng)報(bào)錯(cuò)

spring-boot整合dubbo,調(diào)用方啟動(dòng)報(bào)錯(cuò)

新手初學(xué)Dubbo,在整合Spring-boot做Demo時(shí)候,出現(xiàn)這樣的問題。
服務(wù)提供者可以正常啟動(dòng),調(diào)用方啟動(dòng)失敗。多方嘗試不得其解,無法解決。往過來人給指出問題所在。
下面放出代碼

報(bào)錯(cuò)內(nèi)容
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: #應(yīng)用配置,用于配置當(dāng)前應(yīng)用信息,不管該應(yīng)用是提供者還是消費(fèi)者。
      name: hello-service
    registry: #注冊中心配置,用于配置連接注冊中心相關(guān)信息。
      address: zookeeper://192.168.1.102:2181
    protocol:  #協(xié)議配置,用于配置提供服務(wù)的協(xié)議信息,協(xié)議由提供方指定,消費(fèi)方被動(dòng)接受。
      name: dubbo
      port: 20880
    service:
      interface: cn.mrthree.dubbo.HelloService
      ref: helloService
server:
  port: 8880
調(diào)用方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);
    }
}
調(diào)用方配置
srping:
  dubbo:
    application: #應(yīng)用配置,用于配置當(dāng)前應(yīng)用信息,不管該應(yīng)用是提供者還是消費(fèi)者。
      name: hello-consumer
    registry: #注冊中心配置,用于配置連接注冊中心相關(guān)信息。
      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
回答
編輯回答
放開她

報(bào)錯(cuò)提示的很清楚了

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

個(gè)人認(rèn)為是沒有注入成功 可能是主程序配置未掃描到注解? 可以考慮使用dubbo的@Service注解和spring的注解結(jié)合 springboot本就是為了簡化配置 為什么還用那么多配置呢

2017年11月5日 02:04