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的启动过程又可 ...
随机推荐
- ROC曲线的计算
1.ROC曲线简介 在评价分类模型时,会用到ROC(receiver operating characteristic)曲线.ROC曲线可用来评价二元分类器( binary classifier)的优 ...
- 关于new date()获取服务器时间与linux系统时间不一致的解决办法 2017.12.6
在catalina.sh 第一行添加一下脚本JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8 -Duser.timezone=GMT+08"
- 查找linux设备的uuid
[root@ ~]# blkid /dev/vdc /dev/vdc: UUID="bxxxx-xxx-41b9-8146-7da8bd645b92" TYPE="ext ...
- CentOS6.*安装gitolite
http://www.kankanews.com/ICkengine/archives/64748.shtml 2人收藏此文章, 发表于4小时前(2013-10-22 16:12) , 已有26次阅读 ...
- 再谈DOMContentLoaded与渲染阻塞—分析html页面事件与资源加载
浏览器的多线程中,有的线程负责加载资源,有的线程负责执行脚本,有的线程负责渲染界面,有的线程负责轮询.监听用户事件. 这些线程,根据浏览器自身特点以及web标准等等,有的会被浏览器特意的阻塞.两个很明 ...
- BZOJ_1369_[Baltic2003]Gem_树形DP
BZOJ_1369_[Baltic2003]Gem_树形DP Description 给出一棵树,要求你为树上的结点标上权值,权值可以是任意的正整数 唯一的限制条件是相临的两个结点不能标上相同的权值, ...
- linux系统日志查看
系统 日志文件( 可以通过cat 或tail 命令来查看) /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一/var/log/secure ...
- Windows上安装配置SSH教程(5)——win10下使用Cygwin+Expect自动登陆ssh
1.安装Cygwin,安装上Tcl和Expect两个工具. 可以使用apt-cyg命令安装,也可以在安装Cygwin的时候选中这两个包. 命令安装的话使用下面的两个命令: apt-cyg instal ...
- Https协议与HttpClient的实现
一.背景 HTTP是一个传输内容有可读性的公开协议,客户端与服务器端的数据完全通过明文传输.在这个背景之下,整个依赖于Http协议的互联网数据都是透明的,这带来了很大的数据安全隐患.想要解决这个问题有 ...
- Spring Framework学习要点摘抄
以下摘自Spring Framework官方文档,版本Spring 4.3. <context:annotation-config/> implicitly registered post ...