Annotation Type DubboReference
@Documented
@Retention(RUNTIME)
@Target({FIELD,METHOD,ANNOTATION_TYPE})
public @interface DubboReference
An annotation used for referencing a Dubbo service.
It is recommended to use @DubboReference on the @Bean method in the Java-config class, but not on the fields or setter methods to be injected.
Step 1: Register ReferenceBean in Java-config class:
@Configuration
public class ReferenceConfiguration {
@Bean
@DubboReference(group = "demo")
public ReferenceBean<HelloService> helloService() {
return new ReferenceBean();
}
@Bean
@DubboReference(group = "demo", interfaceClass = HelloService.class)
public ReferenceBean<GenericService> genericHelloService() {
return new ReferenceBean();
}
}
Step 2: Inject ReferenceBean by @Autowired
public class FooController {
@Autowired
private HelloService helloService;
@Autowired
private GenericService genericHelloService;
}
- Since:
- 2.7.7
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionintMaximum active requests allowed, default value is 0Deprecated.This attribute was deprecated, use bind application/module of spring ApplicationContextbooleanWhether to enable async invocation, default value is falseSpecify cache implementation for service invocation, legal values include: lru, threadlocal, jcacheintThe callback instance limit peer connectionbooleanCheck if service provider is available during boot up, default value is trueClient transport type, default value is "netty"Cluster strategy, legal values include: failover, failfast, failsafe, failback, forking you can useClusterRules.FAIL_FAST……intMaximum connections service provider can accept, default value is 0 - connection is sharedConsumer associated nameString[]Filters for service invocationbooleanDeprecated.Do not need specify generic value, judge by injection type and interface classService group, default value is empty stringThe id NOTE: The id attribute is ignored when using @DubboReference on @Bean methodbooleanWhether eager initialize the reference bean when all properties are set, default value is true ( null as true)booleanDeprecated.using scope="local" or scope="remote" insteadClass<?> Interface class, default value is void.classInterface class name, default value is empty stringService layer, default value is empty stringbooleanWhether to make connection when the client is created, the default value is falseString[]Listeners for service exporting and unexportingLoad balance strategy, legal values include: random, roundrobin, leastactive you can useLoadbalanceRules.RANDOM……Service mergerMethod[]methods supportService mock name, use interface name + Mock if not setModule associated nameMonitor associated nameCallback method name when connected, default value is empty stringCallback method name when disconnected, default value is empty stringService owner, default value is empty stringString[]Customized parameter key-value pair, for example: {key1, value1, key2, value2} or {"key1=value1", "key2=value2"}The communication protocol of Dubbo ServiceString[]declares which app or service this interface belongs toassign the namespace that provider belong tointThe service port of the providerHow the proxy is generated, legal values include: jdk, javassistWhether to reconnect if connection is lost, if not specify, reconnect is enabled by default, and the interval for retry connecting is 2000 msbooleanWeather the reference is refer asynchronouslyString[]Registry associated nameintService invocation retry timesthe scope for referring/exporting a service, if it's local, it means searching in current JVM only.booleanWhether the async request has already been sent, the default value is falseString[]Deprecated.usingprovidedBy()booleanWhether to stick to the same node in the cluster, the default value is falseService stub name, use interface name + Stub if not setbooleanExport an stub service for event dispatch, default value is false.Service tag nameintTimeout value for service invocation, default value is 0booleanunload Cluster related in mesh modeService target URL for direct invocation, if this is specified, then registry center takes no effect.Whether to use JSR303 validation, legal values are: true, falseService version, default value is empty string
-
Element Details
-
interfaceClass
Class<?> interfaceClassInterface class, default value is void.class- Default:
void.class
-
interfaceName
String interfaceNameInterface class name, default value is empty string- Default:
""
-
version
String versionService version, default value is empty string- Default:
""
-
group
String groupService group, default value is empty string- Default:
""
-
url
String urlService target URL for direct invocation, if this is specified, then registry center takes no effect.- Default:
""
-
client
String clientClient transport type, default value is "netty"- Default:
""
-
generic
Deprecated.Do not need specify generic value, judge by injection type and interface classWhether to enable generic invocation, default value is false- Default:
false
-
injvm
Deprecated.using scope="local" or scope="remote" insteadWhen enable, prefer to call local service in the same JVM if it's present, default value is true- Default:
true
-
check
boolean checkCheck if service provider is available during boot up, default value is true- Default:
true
-
init
boolean initWhether eager initialize the reference bean when all properties are set, default value is true ( null as true)- See Also:
- Default:
true
-
lazy
boolean lazyWhether to make connection when the client is created, the default value is false- Default:
false
-
stubevent
boolean stubeventExport an stub service for event dispatch, default value is false.see org.apache.dubbo.rpc.Constants#STUB_EVENT_METHODS_KEY
- Default:
false
-
reconnect
String reconnectWhether to reconnect if connection is lost, if not specify, reconnect is enabled by default, and the interval for retry connecting is 2000 mssee org.apache.dubbo.remoting.Constants#DEFAULT_RECONNECT_PERIOD
- Default:
""
-
sticky
boolean stickyWhether to stick to the same node in the cluster, the default value is falsesee Constants#DEFAULT_CLUSTER_STICKY
- Default:
false
-
proxy
String proxyHow the proxy is generated, legal values include: jdk, javassist- Default:
""
-
stub
String stubService stub name, use interface name + Stub if not set- Default:
""
-
cluster
String clusterCluster strategy, legal values include: failover, failfast, failsafe, failback, forking you can useClusterRules.FAIL_FAST……- Default:
""
-
connections
int connectionsMaximum connections service provider can accept, default value is 0 - connection is shared- Default:
-1
-
callbacks
int callbacksThe callback instance limit peer connectionsee org.apache.dubbo.rpc.Constants#DEFAULT_CALLBACK_INSTANCES
- Default:
-1
-
onconnect
String onconnectCallback method name when connected, default value is empty string- Default:
""
-
ondisconnect
String ondisconnectCallback method name when disconnected, default value is empty string- Default:
""
-
owner
String ownerService owner, default value is empty string- Default:
""
-
layer
String layerService layer, default value is empty string- Default:
""
-
retries
int retriesService invocation retry timessee Constants#DEFAULT_RETRIES
- Default:
-1
-
loadbalance
String loadbalanceLoad balance strategy, legal values include: random, roundrobin, leastactive you can useLoadbalanceRules.RANDOM……- Default:
""
-
async
boolean asyncWhether to enable async invocation, default value is false- Default:
false
-
actives
int activesMaximum active requests allowed, default value is 0- Default:
-1
-
sent
boolean sentWhether the async request has already been sent, the default value is false- Default:
false
-
mock
String mockService mock name, use interface name + Mock if not set- Default:
""
-
validation
String validationWhether to use JSR303 validation, legal values are: true, false- Default:
""
-
timeout
int timeoutTimeout value for service invocation, default value is 0- Default:
-1
-
cache
String cacheSpecify cache implementation for service invocation, legal values include: lru, threadlocal, jcache- Default:
""
-
filter
String[] filterFilters for service invocationsee Filter
- Default:
{}
-
listener
String[] listenerListeners for service exporting and unexportingsee ExporterListener
- Default:
{}
-
parameters
String[] parametersCustomized parameter key-value pair, for example: {key1, value1, key2, value2} or {"key1=value1", "key2=value2"}- Default:
{}
-
application
Deprecated.This attribute was deprecated, use bind application/module of spring ApplicationContextApplication name- Default:
""
-
module
String moduleModule associated name- Default:
""
-
consumer
String consumerConsumer associated name- Default:
""
-
monitor
String monitorMonitor associated name- Default:
""
-
registry
String[] registryRegistry associated name- Default:
{}
-
protocol
String protocolThe communication protocol of Dubbo Service- Returns:
- the default value is ""
- Since:
- 2.6.6
- Default:
""
-
tag
String tagService tag name- Default:
""
-
merger
String mergerService merger- Default:
""
-
methods
Method[] methodsmethods support- Default:
{}
-
id
String idThe id NOTE: The id attribute is ignored when using @DubboReference on @Bean method- Returns:
- default value is empty
- Since:
- 2.7.3
- Default:
""
-
services
Deprecated.usingprovidedBy()- Returns:
- The service names that the Dubbo interface subscribed
- Since:
- 2.7.8
- See Also:
- Default:
{}
-
providedBy
String[] providedBydeclares which app or service this interface belongs to- See Also:
- Default:
{}
-
providerPort
int providerPortThe service port of the provider- Since:
- 3.1.0
- See Also:
- Default:
-1
-
providerNamespace
String providerNamespaceassign the namespace that provider belong to- Since:
- 3.1.1
- See Also:
- Default:
""
-
scope
String scopethe scope for referring/exporting a service, if it's local, it means searching in current JVM only.- See Also:
- Default:
""
-
referAsync
boolean referAsyncWeather the reference is refer asynchronously- Default:
false
-
unloadClusterRelated
boolean unloadClusterRelatedunload Cluster related in mesh mode- Since:
- 3.1.0
- See Also:
- Default:
false
-