前言

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

@Reference

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
public @interface Reference {
/**
* Interface class, default value is void.class
*/
Class<?> interfaceClass() default void.class; /**
* Interface class name, default value is empty string
*/
String interfaceName() default ""; /**
* Service version, default value is empty string
*/
String version() default ""; /**
* Service group, default value is empty string
*/
String group() default ""; /**
* Service target URL for direct invocation, if this is specified, then registry center takes no effect.
   * 不使用注册中心,消费者和提供者直连,url="dubbo://localhost:20890"
*/
String url() default ""; /**
* Client transport type, default value is "netty"
*/
String client() default ""; /**
* Whether to enable generic invocation, default value is false
*/
boolean generic() default false; /**
* When enable, prefer to call local service in the same JVM if it's present, default value is true
*/
boolean injvm() default true; /**
* Check if service provider is available during boot up, default value is true
*/
boolean check() default true; /**
* Whether eager initialize the reference bean when all properties are set, default value is false
*/
boolean init() default false; /**
* Whether to make connection when the client is created, the default value is false
*/
boolean lazy() default false; /**
* Export an stub service for event dispatch, default value is false.
*
* @see Constants#STUB_EVENT_METHODS_KEY
*/
boolean stubevent() default false; /**
* Whether to reconnect if connection is lost, if not specify, reconnect is enabled by default, and the interval
* for retry connecting is 2000 ms
*
* @see Constants#DEFAULT_RECONNECT_PERIOD
*/
String reconnect() default ""; /**
* Whether to stick to the same node in the cluster, the default value is false
*
* @see Constants#DEFAULT_CLUSTER_STICKY
*/
boolean sticky() default false; /**
* How the proxy is generated, legal values include: jdk, javassist
*/
String proxy() default ""; /**
* Service stub name, use interface name + Local if not set
*/
String stub() default ""; /**
* Cluster strategy, legal values include: failover, failfast, failsafe, failback, forking
*/
String cluster() default ""; /**
* Maximum connections service provider can accept, default value is 0 - connection is shared
*/
int connections() default 0; /**
* The callback instance limit peer connection
*
* @see Constants#DEFAULT_CALLBACK_INSTANCES
*/
int callbacks() default 0; /**
* Callback method name when connected, default value is empty string
*/
String onconnect() default ""; /**
* Callback method name when disconnected, default value is empty string
*/
String ondisconnect() default ""; /**
* Service owner, default value is empty string
*/
String owner() default ""; /**
* Service layer, default value is empty string
*/
String layer() default ""; /**
* Service invocation retry times
*
* @see Constants#DEFAULT_RETRIES
*/
int retries() default 2; /**
* Load balance strategy, legal values include: random, roundrobin, leastactive
*
* @see Constants#DEFAULT_LOADBALANCE
*/
String loadbalance() default ""; /**
* Whether to enable async invocation, default value is false
*/
boolean async() default false; /**
* Maximum active requests allowed, default value is 0
*/
int actives() default 0; /**
* Whether the async request has already been sent, the default value is false
*/
boolean sent() default false; /**
* Service mock name, use interface name + Mock if not set
*/
String mock() default ""; /**
* Whether to use JSR303 validation, legal values are: true, false
*/
String validation() default ""; /**
* Timeout value for service invocation, default value is 0
*/
int timeout() default 0; /**
* Specify cache implementation for service invocation, legal values include: lru, threadlocal, jcache
*/
String cache() default ""; /**
* Filters for service invocation
*
* @see Filter
*/
String[] filter() default {}; /**
* Listeners for service exporting and unexporting
*
* @see ExporterListener
*/
String[] listener() default {}; /**
* Customized parameter key-value pair, for example: {key1, value1, key2, value2}
*/
String[] parameters() default {}; /**
* Application spring bean name
*/
String application() default ""; /**
* Module spring bean name
*/
String module() default ""; /**
* Consumer spring bean name
*/
String consumer() default ""; /**
* Monitor spring bean name
*/
String monitor() default ""; /**
* Registry spring bean name
*/
String[] registry() default {}; /**
* Protocol spring bean names
*/
String protocol() default ""; /**
* methods support
* @return
*/
Method[] methods() default {};
}

@Service

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Inherited
public @interface Service { /**
* Interface class, default value is void.class
*/
Class<?> interfaceClass() default void.class; /**
* Interface class name, default value is empty string
*/
String interfaceName() default ""; /**
* Service version, default value is empty string
*/
String version() default ""; /**
* Service group, default value is empty string
*/
String group() default ""; /**
* Service path, default value is empty string
*/
String path() default ""; /**
* Whether to export service, default value is true
*/
boolean export() default true; /**
* Service token, default value is false
*/
String token() default ""; /**
* Whether the service is deprecated, default value is false
*/
boolean deprecated() default false; /**
* Whether the service is dynamic, default value is false
*/
boolean dynamic() default false; /**
* Access log for the service, default value is ""
*/
String accesslog() default ""; /**
* Maximum concurrent executes for the service, default value is 0 - no limits
*/
int executes() default 0; /**
* Whether to register the service to register center, default value is true
*/
boolean register() default true; /**
* Service weight value, default value is 0
*/
int weight() default 0; /**
* Service doc, default value is ""
*/
String document() default ""; /**
* Delay time for service registration, default value is 0
*/
int delay() default 0; /**
* @see Service#stub()
* @deprecated
*/
String local() default ""; /**
* Service stub name, use interface name + Local if not set
*/
String stub() default ""; /**
* Cluster strategy, legal values include: failover, failfast, failsafe, failback, forking
*/
String cluster() default ""; /**
* How the proxy is generated, legal values include: jdk, javassist
*/
String proxy() default ""; /**
* Maximum connections service provider can accept, default value is 0 - connection is shared
*/
int connections() default 0; /**
* The callback instance limit peer connection
*
* @see Constants#DEFAULT_CALLBACK_INSTANCES
*/
int callbacks() default Constants.DEFAULT_CALLBACK_INSTANCES; /**
* Callback method name when connected, default value is empty string
*/
String onconnect() default ""; /**
* Callback method name when disconnected, default value is empty string
*/
String ondisconnect() default ""; /**
* Service owner, default value is empty string
*/
String owner() default ""; /**
* Service layer, default value is empty string
*/
String layer() default ""; /**
* Service invocation retry times
*
* @see Constants#DEFAULT_RETRIES
*/
int retries() default Constants.DEFAULT_RETRIES; /**
* Load balance strategy, legal values include: random, roundrobin, leastactive
*
* @see Constants#DEFAULT_LOADBALANCE
*/
String loadbalance() default Constants.DEFAULT_LOADBALANCE; /**
* Whether to enable async invocation, default value is false
*/
boolean async() default false; /**
* Maximum active requests allowed, default value is 0
*/
int actives() default 0; /**
* Whether the async request has already been sent, the default value is false
*/
boolean sent() default false; /**
* Service mock name, use interface name + Mock if not set
*/
String mock() default ""; /**
* Whether to use JSR303 validation, legal values are: true, false
*/
String validation() default ""; /**
* Timeout value for service invocation, default value is 0
*/
int timeout() default 0; /**
* Specify cache implementation for service invocation, legal values include: lru, threadlocal, jcache
*/
String cache() default ""; /**
* Filters for service invocation
*
* @see Filter
*/
String[] filter() default {}; /**
* Listeners for service exporting and unexporting
*
* @see ExporterListener
*/
String[] listener() default {}; /**
* Customized parameter key-value pair, for example: {key1, value1, key2, value2}
*/
String[] parameters() default {}; /**
* Application spring bean name
*/
String application() default ""; /**
* Module spring bean name
*/
String module() default ""; /**
* Provider spring bean name
*/
String provider() default ""; /**
* Protocol spring bean names
*/
String[] protocol() default {}; /**
* Monitor spring bean name
*/
String monitor() default ""; /**
* Registry spring bean name
*/
String[] registry() default {}; /**
* Service tag name
*/
String tag() default ""; /**
* methods support
* @return
*/
Method[] methods() default {};
}

Dubbo的@Reference和@Service说明的更多相关文章

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

    @Reference 用在消费端,表明使用的是服务端的什么服务@RestControllerpublic class RemoteUserController { @Reference(version ...

  2. springMVC dubbo注解无效,service层返回空指针

    出现空指针的原因是:spring mvc扫描的时候根本无法识别@Reference ,同一方面,dubbo的扫描也无法识别Spring @Controller ,所以两个扫描的顺序要排列好,  如果先 ...

  3. Spring-Boot 整合Dubbo 解决@Reference 注解为null情况

    首先检查一下你的spring boot版本是多少? 如果是2.X 不用看了,spring boot 2.x 必定会出现这个问题, 改为 1.5.9 或其他1.x版本,目前生产环境建议使用1.x版本. ...

  4. 关于dubbo调度时出现Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method insertTestTb in the service cn.cuibusi.core.service.TestTbService.的解决办法

    在用dubbo跨项目调度service时出现如下错误: 错误原因:pojo没有实现序列化 解决方法:在pojo实现序列化接口即可

  5. dubbo错误排查之No provider available for the service

    今天搞的一个dubbo服务,暴漏出来了,但是consumer端启动就报这个错,排查过程记录一下 一.启动zkCli 利用命令查看 ls / ls /dubbo 继续查看 ls /dubbo/com.w ...

  6. 基于dubbo构建分布式项目与服务模块

      关于分布式服务架构的背景和需求可查阅http://dubbo.io/.不同于传统的单工程项目,本文主要学习如何通过maven和dubbo将构建分布项目以及服务模块,下面直接开始. 创建项目以及模块 ...

  7. Dubbo入门实例--转载

    原文地址:http://blog.csdn.net/ruishenh/article/details/23180707?utm_source=tuicool 1.   概述 Dubbo是一个分布式服务 ...

  8. dubbo简述

    转http://blog.csdn.net/hzzhoushaoyu/article/details/4327309 一.前言 部门去年年中开始各种改造,第一步是模块服务化,这边初选dubbo试用在一 ...

  9. Spring Dubbo 开发笔记

    第一节:概述 Spring-Dubbo 是我自己写的一个基于spring-boot和dubbo,目的是使用Spring boot的风格来使用dubbo.(即可以了解Spring boot的启动过程又可 ...

随机推荐

  1. ansj原子切分和全切分

    ansj第一步会进行原子切分和全切分,并且是在同时进行的.所谓原子,是指短句中不可分割的最小语素单位.例如,一个汉字就是一个原子.全切分,就是把一句话中的所有词都找出来,只要是字典中有的就找出来.例如 ...

  2. 错误 C2280 Union : 尝试引用已删除的函数 以及 警告 C4624 “Grade”: 已将析构函数隐式定义为“已删除”的一种解决方法

    Union 是C/C++语言中的一种结构类型,用于定义可共享内存的数据变量的一种方式,初次使用Union联合体时可能会遇到以下问题: 错误 C2280 Union : 尝试引用已删除的函数 警告 C4 ...

  3. U型理论

  4. 关于jquery日期控件及时间格式转换2017.05.27

    开始时间:<input type="date" id="starttime" class="time"/>//data为日期控件 ...

  5. redis与python交互

    import redis #连接 r=redis.StrictRedis(host="localhost",port=6379,password="sunck" ...

  6. 一个js小游戏----总结

    花了大概一天左右的功夫实现了一个js小游戏的基本功能,类似于“雷电”那样的小游戏,实现了随即怪物发生器,碰撞检测,运动等等都实现了,下一个功能是子弹轨迹,还有其他一些扩展功能,没有用库,也没有用web ...

  7. redis结合自定义注解实现基于方法的注解缓存,及托底缓存的实现

    本次分享如何使用redis结合自定义注解实现基于方法的注解缓存,及托底缓存的实现思路    现在的互联网公司大多数都是以Redis作为缓存,使用缓存的优点就不赘述了,写这篇文章的目的就是想帮助同学们如 ...

  8. [Poi2012]A Horrible Poem BZOJ2795

    分析: 这是今天下午的考试题,推了2个小时,考试中A掉了 首先,循环串通过字符串hash可以O(1)判断:get_hash(l,r-len)==get_hash(l+len,r);显然可证. 我们其次 ...

  9. 【游戏开发】小白学Lua——从Lua查找表元素的过程看元表、元方法

    引言 在上篇博客中,我们简单地学习了一下Lua的基本语法.其实在Lua中有一个还有一个叫元表的概念,不得不着重地探讨一下.元表在实际地开发中,也是会被极大程度地所使用到.本篇博客,就让我们从Lua查找 ...

  10. MongoDB面试题

    1.什么是MongoDB MongoDB是一个文档数据库,提供好的性能,领先的非关系型数据库.采用BSON存储文档数据.BSON()是一种类json的一种二进制形式的存储格式,简称Binary JSO ...