Dubbo的@Reference和@Service說明---1Reference用在消費者2Service用在提供者【import com.alibaba.dubbo.config.annotation.Service;】


@Reference 用在消費端,表明使用的是服務端的什么服務@RestController
public class RemoteUserController {



    @Reference(version = "1.0.0",check = true)
    private RemoteUserService remoteUserService;



    @RequestMapping(value="/dubbo/say/{name}")
    public String sayHello(@PathVariable("name") String name){
        //調用服務提供者的服務
        String result=remoteUserService.sayHello(name);
        return result;
    }
}

@Service 用在服務提供者中,在類或者接口中聲明。
服務提供者實現相關的服務接口,當消費端調用相關的類時,最終會調用提供者的實現方法。
@Component
@Service(version = "1.0.0",timeout = 10000,interfaceClass = RemoteUserService.class)
public class RemoteUserServiceImpl implements RemoteUserService {

    @Override
    public String sayHello(String name) {

        log.info("訪問sayHello " + name);
        return "Hello " + name;
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM