Dubbo的@Reference和@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;
}
}
@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说明的更多相关文章
- Dubbo的@Reference和@Service说明---1Reference用在消费者2Service用在提供者【import com.alibaba.dubbo.config.annotation.Service;】
@Reference 用在消费端,表明使用的是服务端的什么服务@RestControllerpublic class RemoteUserController { @Reference(version ...
- springMVC dubbo注解无效,service层返回空指针
出现空指针的原因是:spring mvc扫描的时候根本无法识别@Reference ,同一方面,dubbo的扫描也无法识别Spring @Controller ,所以两个扫描的顺序要排列好, 如果先 ...
- Spring-Boot 整合Dubbo 解决@Reference 注解为null情况
首先检查一下你的spring boot版本是多少? 如果是2.X 不用看了,spring boot 2.x 必定会出现这个问题, 改为 1.5.9 或其他1.x版本,目前生产环境建议使用1.x版本. ...
- 关于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实现序列化接口即可
- dubbo错误排查之No provider available for the service
今天搞的一个dubbo服务,暴漏出来了,但是consumer端启动就报这个错,排查过程记录一下 一.启动zkCli 利用命令查看 ls / ls /dubbo 继续查看 ls /dubbo/com.w ...
- 基于dubbo构建分布式项目与服务模块
关于分布式服务架构的背景和需求可查阅http://dubbo.io/.不同于传统的单工程项目,本文主要学习如何通过maven和dubbo将构建分布项目以及服务模块,下面直接开始. 创建项目以及模块 ...
- Dubbo入门实例--转载
原文地址:http://blog.csdn.net/ruishenh/article/details/23180707?utm_source=tuicool 1. 概述 Dubbo是一个分布式服务 ...
- dubbo简述
转http://blog.csdn.net/hzzhoushaoyu/article/details/4327309 一.前言 部门去年年中开始各种改造,第一步是模块服务化,这边初选dubbo试用在一 ...
- Spring Dubbo 开发笔记
第一节:概述 Spring-Dubbo 是我自己写的一个基于spring-boot和dubbo,目的是使用Spring boot的风格来使用dubbo.(即可以了解Spring boot的启动过程又可 ...
随机推荐
- Linux时间子系统之四:Timer在用户和内核空间流程
用户空间应用中创建一个Timer(alarm/setitimer/POSIX Timer等等),然后程序继续执行: 内核进入创建/设置Timer系统调用,开始计时,在超时后通过何种方式通知用户空间: ...
- Jodd
Jodd = tools + ioc + mvc + db + aop + tx + json + html < 1.7 Mb Jodd is set of Java microframewor ...
- CSS3 :nth-child() 选择器---挖坑
E:nth-child(n) 语法: E:nth-child(n) { sRules } 说明: 匹配父元素的第n个子元素E,假设该子元素不是E,则选择符无效.(也就是说,会检查从body开始的每个元 ...
- css中的单冒号和双冒号
最近突然被别人问起css单冒号和双冒号有什么区别,答曰:"不知道". 虽然还在填坑中,但作为一个跨过了初级的FEer,感觉着实汗颜,刚好今天下午在搜别的问题的时候,突然看到一个对比 ...
- fixed元素随滚动条无抖动滚动
页面上用fixed定位一个元素,随滚动条滚动位置不变,最开始我只用了css给元素身上写上fixed属性,发现滚动时元素会发生抖动,随后我就在网上找到解决办法,封装了个方法,如下: Css部分 此部分是 ...
- BITE
<Google软件测试之道> 读后感言: p147 提到的BITE实在是太让人心动了, 一个简单的动作即可提交一个信息齐全的bug,连非专业测试人员也能轻松做到.身边很多人也都碰到过提交b ...
- 关于Kafka __consumer_offests的讨论
众所周知,__consumer__offsets是一个内部topic,对用户而言是透明的,除了它的数据文件以及偶尔在日志中出现这两点之外,用户一般是感觉不到这个topic的.不过我们的确知道它保存的是 ...
- BZOJ_4320_ShangHai2006 Homework_分块
BZOJ_4320_ShangHai2006 Homework_分块 Description 1:在人物集合 S 中加入一个新的程序员,其代号为 X,保证 X 在当前集合中不存在. 2:在当 ...
- AMBA总线协议AHB、APB
一.什么是AMBA总线 AMBA总线规范是ARM公司提出的总线规范,被大多数SoC设计采用,它规定了AHB (Advanced High-performance Bus).ASB (Advanced ...
- Centos 7 Linux系统修改网卡名称为ethx
一.Centos7 系统安装完成后更改网卡名称方法 1.查看Centos7系统默认的网卡配置(eno16777736) [root@server ~]# ifconfig eno16777736: f ...