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 Elements
    Modifier and Type
    Optional Element
    Description
    int
    Maximum active requests allowed, default value is 0
    Deprecated.
    This attribute was deprecated, use bind application/module of spring ApplicationContext
    boolean
    Whether to enable async invocation, default value is false
    Specify cache implementation for service invocation, legal values include: lru, threadlocal, jcache
    int
    The callback instance limit peer connection
    boolean
    Check if service provider is available during boot up, default value is true
    Client transport type, default value is "netty"
    Cluster strategy, legal values include: failover, failfast, failsafe, failback, forking you can use ClusterRules.FAIL_FAST ……
    int
    Maximum connections service provider can accept, default value is 0 - connection is shared
    Consumer associated name
    Filters for service invocation
    boolean
    Deprecated.
    Do not need specify generic value, judge by injection type and interface class
    Service group, default value is empty string
    The id NOTE: The id attribute is ignored when using @DubboReference on @Bean method
    boolean
    Whether eager initialize the reference bean when all properties are set, default value is true ( null as true)
    boolean
    Deprecated.
    using scope="local" or scope="remote" instead
    Interface class, default value is void.class
    Interface class name, default value is empty string
    Service layer, default value is empty string
    boolean
    Whether to make connection when the client is created, the default value is false
    Listeners for service exporting and unexporting
    Load balance strategy, legal values include: random, roundrobin, leastactive you can use LoadbalanceRules.RANDOM ……
    Service merger
    methods support
    Service mock name, use interface name + Mock if not set
    Module associated name
    Monitor associated name
    Callback method name when connected, default value is empty string
    Callback method name when disconnected, default value is empty string
    Service owner, default value is empty string
    Customized parameter key-value pair, for example: {key1, value1, key2, value2} or {"key1=value1", "key2=value2"}
    The communication protocol of Dubbo Service
    declares which app or service this interface belongs to
    assign the namespace that provider belong to
    int
    The service port of the provider
    How the proxy is generated, legal values include: jdk, javassist
    Whether to reconnect if connection is lost, if not specify, reconnect is enabled by default, and the interval for retry connecting is 2000 ms
    boolean
    Weather the reference is refer asynchronously
    Registry associated name
    int
    Service invocation retry times
    the scope for referring/exporting a service, if it's local, it means searching in current JVM only.
    boolean
    Whether the async request has already been sent, the default value is false
    Deprecated.
    boolean
    Whether to stick to the same node in the cluster, the default value is false
    Service stub name, use interface name + Stub if not set
    boolean
    Export an stub service for event dispatch, default value is false.
    Service tag name
    int
    Timeout value for service invocation, default value is 0
    boolean
    unload Cluster related in mesh mode
    Service target URL for direct invocation, if this is specified, then registry center takes no effect.
    Whether to use JSR303 validation, legal values are: true, false
    Service version, default value is empty string
  • Element Details

    • interfaceClass

      Class<?> interfaceClass
      Interface class, default value is void.class
      Default:
      void.class
    • interfaceName

      String interfaceName
      Interface class name, default value is empty string
      Default:
      ""
    • version

      String version
      Service version, default value is empty string
      Default:
      ""
    • group

      String group
      Service group, default value is empty string
      Default:
      ""
    • url

      String url
      Service target URL for direct invocation, if this is specified, then registry center takes no effect.
      Default:
      ""
    • client

      String client
      Client transport type, default value is "netty"
      Default:
      ""
    • generic

      @Deprecated boolean generic
      Deprecated.
      Do not need specify generic value, judge by injection type and interface class
      Whether to enable generic invocation, default value is false
      Default:
      false
    • injvm

      @Deprecated boolean injvm
      Deprecated.
      using scope="local" or scope="remote" instead
      When enable, prefer to call local service in the same JVM if it's present, default value is true
      Default:
      true
    • check

      boolean check
      Check if service provider is available during boot up, default value is true
      Default:
      true
    • init

      boolean init
      Whether eager initialize the reference bean when all properties are set, default value is true ( null as true)
      See Also:
      Default:
      true
    • lazy

      boolean lazy
      Whether to make connection when the client is created, the default value is false
      Default:
      false
    • stubevent

      boolean stubevent
      Export an stub service for event dispatch, default value is false.

      see org.apache.dubbo.rpc.Constants#STUB_EVENT_METHODS_KEY

      Default:
      false
    • reconnect

      String reconnect
      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 org.apache.dubbo.remoting.Constants#DEFAULT_RECONNECT_PERIOD

      Default:
      ""
    • sticky

      boolean sticky
      Whether to stick to the same node in the cluster, the default value is false

      see Constants#DEFAULT_CLUSTER_STICKY

      Default:
      false
    • proxy

      String proxy
      How the proxy is generated, legal values include: jdk, javassist
      Default:
      ""
    • stub

      String stub
      Service stub name, use interface name + Stub if not set
      Default:
      ""
    • cluster

      String cluster
      Cluster strategy, legal values include: failover, failfast, failsafe, failback, forking you can use ClusterRules.FAIL_FAST ……
      Default:
      ""
    • connections

      int connections
      Maximum connections service provider can accept, default value is 0 - connection is shared
      Default:
      -1
    • callbacks

      int callbacks
      The callback instance limit peer connection

      see org.apache.dubbo.rpc.Constants#DEFAULT_CALLBACK_INSTANCES

      Default:
      -1
    • onconnect

      String onconnect
      Callback method name when connected, default value is empty string
      Default:
      ""
    • ondisconnect

      String ondisconnect
      Callback method name when disconnected, default value is empty string
      Default:
      ""
    • owner

      String owner
      Service owner, default value is empty string
      Default:
      ""
    • layer

      String layer
      Service layer, default value is empty string
      Default:
      ""
    • retries

      int retries
      Service invocation retry times

      see Constants#DEFAULT_RETRIES

      Default:
      -1
    • loadbalance

      String loadbalance
      Load balance strategy, legal values include: random, roundrobin, leastactive you can use LoadbalanceRules.RANDOM ……
      Default:
      ""
    • async

      boolean async
      Whether to enable async invocation, default value is false
      Default:
      false
    • actives

      int actives
      Maximum active requests allowed, default value is 0
      Default:
      -1
    • sent

      boolean sent
      Whether the async request has already been sent, the default value is false
      Default:
      false
    • mock

      String mock
      Service mock name, use interface name + Mock if not set
      Default:
      ""
    • validation

      String validation
      Whether to use JSR303 validation, legal values are: true, false
      Default:
      ""
    • timeout

      int timeout
      Timeout value for service invocation, default value is 0
      Default:
      -1
    • cache

      String cache
      Specify cache implementation for service invocation, legal values include: lru, threadlocal, jcache
      Default:
      ""
    • filter

      String[] filter
      Filters for service invocation

      see Filter

      Default:
      {}
    • listener

      String[] listener
      Listeners for service exporting and unexporting

      see ExporterListener

      Default:
      {}
    • parameters

      String[] parameters
      Customized parameter key-value pair, for example: {key1, value1, key2, value2} or {"key1=value1", "key2=value2"}
      Default:
      {}
    • application

      @Deprecated String application
      Deprecated.
      This attribute was deprecated, use bind application/module of spring ApplicationContext
      Application name
      Default:
      ""
    • module

      String module
      Module associated name
      Default:
      ""
    • consumer

      String consumer
      Consumer associated name
      Default:
      ""
    • monitor

      String monitor
      Monitor associated name
      Default:
      ""
    • registry

      String[] registry
      Registry associated name
      Default:
      {}
    • protocol

      String protocol
      The communication protocol of Dubbo Service
      Returns:
      the default value is ""
      Since:
      2.6.6
      Default:
      ""
    • tag

      String tag
      Service tag name
      Default:
      ""
    • merger

      String merger
      Service merger
      Default:
      ""
    • methods

      Method[] methods
      methods support
      Default:
      {}
    • id

      String id
      The 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 String[] services
      Deprecated.
      Returns:
      The service names that the Dubbo interface subscribed
      Since:
      2.7.8
      See Also:
      Default:
      {}
    • providedBy

      String[] providedBy
      declares which app or service this interface belongs to
      See Also:
      Default:
      {}
    • providerPort

      int providerPort
      The service port of the provider
      Since:
      3.1.0
      See Also:
      Default:
      -1
    • providerNamespace

      String providerNamespace
      assign the namespace that provider belong to
      Since:
      3.1.1
      See Also:
      Default:
      ""
    • scope

      String scope
      the scope for referring/exporting a service, if it's local, it means searching in current JVM only.
      See Also:
      • Constants.SCOPE_LOCAL
      • Constants.SCOPE_REMOTE
      Default:
      ""
    • referAsync

      boolean referAsync
      Weather the reference is refer asynchronously
      Default:
      false
    • unloadClusterRelated

      boolean unloadClusterRelated
      unload Cluster related in mesh mode
      Since:
      3.1.0
      See Also:
      Default:
      false