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的启动过程又可 ...
随机推荐
- Windows上使用Git托管代码到Coding
作者:荒原之梦 Git简介: Git是一款分布式版本控制系统,可用于项目的版本管理.Git可以管理本地代码仓库与远程代码仓库间的连接以及进行版本控制,使得我们可以在本地离线进行修改等操作,之后再将代码 ...
- java基础之接口(抽象类与接口的区别)
概述 猫狗案例,我们想想狗一般就是看门,猫一般就是作为宠物了,对不.但是,现在有很多的驯养员或者是驯的,这应该属于经过特殊的培训训练出来的,对不.所以,这些额外的动作定义到动物类中就不合适,也不适合直 ...
- 20.如何从app业务逻辑提炼api接口
在app后端的工作中,设计api是一个很考验设计能力的工作.在项目的初始阶段,只知道具体的业务逻辑,那怎么把业务逻辑抽象和提炼,设计出api呢?通过阅读本文,可解答以上疑惑. 在本文中,是用以前做过的 ...
- 最近最久未使用页面淘汰算法———LRU算法(java实现)
请珍惜小编劳动成果,该文章为小编原创,转载请注明出处. LRU算法,即Last Recently Used ---选择最后一次访问时间距离当前时间最长的一页并淘汰之--即淘汰最长时间没有使用的页 按照 ...
- centos7服务器无GUI情况下安装使用Xvfb、selenium、chrome和selenium-server
最近需要用到selenium浏览器抓取,在windows下对照chrome浏览器开发的代码,在linux服务器上换成phantomjs驱动后,却不能运行了,通过截图发现phantomjs渲染效果和ch ...
- 如何解决-win7系统打开截图工具显示“截图工具当前未在计算机上运行”
打开win7系统自带截图工具,显示"截图工具当前未在计算机上运行.请重新启动计算机,然后重试", 解决方法 1.首先在C盘中搜索tpcps.dll: 2.将数据最大那个tpcp ...
- Java 中的纤程库 – Quasar
来源:鸟窝, colobu.com/2016/07/14/Java-Fiber-Quasar/ 如有好文章投稿,请点击 → 这里了解详情 最近遇到的一个问题大概是微服务架构中经常会遇到的一个问题: 服 ...
- [SCOI2005]栅栏 二分+dfs
这个题真的是太nb了,各种骚 二分答案,肯定要减最小的mid个,从大往小搜每一个木板,从大往小枚举所用的木材 当当前木材比最短的木板还短,就扔到垃圾堆里,并记录waste,当 waste+sum> ...
- Opencv(C++)实现邻近插值算法
#include <opencv2/opencv.hpp> using namespace std; using namespace cv; void Zero_order(const M ...
- java的Integer与int的比较