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内存使用与性能优化》笔记
这本书有两个关切点:系统内存(用户层)和性能优化. 这本书和Brendan Gregg的<Systems Performance>相比,无论是技术层次还是更高的理论都有较大差距.但是这不影 ...
- spring boot -Properties & configuration
72. Properties & configuration72.1 Automatically expand properties at build timeRather than hard ...
- 在腾讯云(windows)上搭建node.js服务器
1:安装Node.js 使用MSI文件,并按照提示安装node.js,默认情况下,安装程序将 Node.js 发行到 C:\Program Files\nodejs. 但这里我们需要修改安装路径到:D ...
- 浅谈前端中的mvvm与mvc
用了vue这么久,却没有认真的关注mvvm与mvc,着实汗颜.趁着周末刚好看了一下网上的文章还有书籍,简单的谈一下我的理解. -以下图片均摘自网络. 一.MVC 特点:单项通讯 视图(View):用户 ...
- spring的依赖注入是什么意思
最近学习spring框架,对依赖注入有些模糊,遂上网翻阅资料,做了下列总结,原博客为CSDN 南夏的 spring的依赖注入是什么意思,侵删! Spring 能有效地组织J2EE应用各层的对象.不管是 ...
- Tornado框架实现图形验证码功能
图形验证码是项目开发过程中经常遇到的一个功能,在很多语言中都有对应的不同形式的图形验证码功能的封装,python 中同样也有类似的封装操作,通过绘制生成一个指定的图形数据,让前端HTML页面通过链接获 ...
- java的classpath路径中加点号 ‘.’ 的作用
"."表示当前目录,就是编译或者执行程序时你所在的目录下的.class文件:而JAvA_HOME表示JDK安装路径 该路径在eclipse中是以vmarg的形式传入的,可以在任务管 ...
- util.go
packagesego import( "bytes" "fmt" ) //输出分词结果为字符串 // //有两种输出模式,以"中华人 ...
- index.go
package types type DocumentIndex struct { // 文本的DocId DocId uint64 // 文本的关键词长 TokenL ...
- 【功耗测试环境预置自动化脚本开发】【切换wifi模式为siso模式】【用到方法*args】
import os,reimport logginglogging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[ ...