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;
    }
}

猜你喜欢

转载自www.cnblogs.com/wym591273/p/10968075.html