This article is more than one year old. Older articles may contain outdated content. Check that the information in the page has not become incorrect since its publication.

Dubbo Basic Usage -- Dubbo Provider Configuration

This article will introduce you how to config Dubbo, by XML, property files, annotations or Java code.

This chapter mainly talking about how to configure dubbo. According to the configuration mode, it can be divided into the following mode: XML Configuration, Properties Configuration, Annotation Configuration, API Invocation Mode Configuration. And according to the function, we can divide them into Dubbo Provider and Dubbo Consumer. In the following sections, we would explain Dubbo Provider and Dubbo Consumer respectively.

Dubbo Provider Configuration

Provider Configuration in Detail

The configuration mode of Dubbo Provider has 4 different ways: XML Configuration, Properties Configuration, API Invocation Mode Configuration and Annotation Configuration.

XML Configuration

The simplest configuration example:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    <dubbo:application name="hello-world-app" />  
    <dubbo:registry address="multicast://" />  
    <dubbo:protocol name="dubbo" port="20880" />  
    <dubbo:service interface="" ref="demoServiceLocal" />  
    <dubbo:reference id="demoServiceRemote" interface="" />  

In the example above,note the way to write dubbo schema:

<beans xmlns:xsi=""
Supported Configuration Tags
<dubbo:service/>Service ConfigurationExpose a service, define the meta information of the service. One service can use multiple protocols to expose and can be registered to multiple registry centers
<dubbo:reference/>Reference ConfigurationCreate a remote service agent, one reference can point to multiple registry centers
<dubbo:protocol/>Protocol ConfigurationConfigure protocol information for providing services, protocol is specified by the provider and accepted passively by the consumer
<dubbo:application/>Application ConfigurationConfigure current application information, regardless of whether the application is provider or consumer
<dubbo:module/>Module ConfigurationConfigure current module information. Optional
<dubbo:registry/>Registry Center ConfigurationConfigure information related to connect registry centers
<dubbo:monitor/>Monitoring Center ConfigurationConfigure information related to connect monitor centers. Optional
<dubbo:provider/>Provider ConfigurationWhen some properties ProtocolConfig or ServiceConfig are not configured, use this default value. Optional
<dubbo:consumer/>Consumer ConfigurationWhen some properties of ReferenceConfig are not configured, use this default value. Optional
<dubbo:method/>Method ConfigurationConfigure specific method level information of ServiceConfig and ReferenceConfig
<dubbo:argument/>Parameter ConfigurationConfigure parameters of specific method


Configuration Diagram

Configuration item in detail
  • <dubbo:application name=“hello-world-app” />
    Apply to specific application name, note that you need to make sure that the application name is unique. The application name can be displayed in the following console admin for easy management.

  • <dubbo:registry address=“multicast://” />
    Configure registry center, related to the specific mechanism of service discovery. It can be zookeeper address or eureka address. The address above is the broadcast address, which is very convenient in the test process of the local service invocation.

  • <dubbo:protocol name=“dubbo” port=“20880” />
    Here is the transport protocol and the default port, generally no changes are required.

Next, we will focus on the configuration of <dubbo:service/>

  • <dubbo:service/>mainly supports the following properties:
Properties NameDescription
versionVersion number
scopeService visibility, value can be local or remote,remote by default
activesMaximum number of activated requests
asyncWhether the method called asynchronously,false by default
cacheService cache,optional value:lru/threadlocal/jcache
callbacksLimitation of callback instance
genericGeneralized calls which can be bypassed
classThe implementation of the service’s class name
connectionsThe number of connections in the service
delayThe number of milliseconds delay for publicating the service
executesUpper bound of service execution requests
retriesTimeout retry times
timeoutInvocation timeout time

For other configuration properties, please refer to xsd:

  • <dubbo:method/> as the sub-element of <dubbo:service/> can be configured corresponding to method. Properties that are commonly used are:
Properties NameDescription
executesUpper bound of service execution requests
retriesTimeout retry times
timeoutInvocation timeout time

For other properties,you can refer to xsd above。

Configuration Override Relationship


Configuration Coverage Relationship Diagram

The Override relationship here includes the configuration of both provider end and consumer end. If you have any questions about consumer, you can refer to the next chapter, consumer chapter, to understand. Configuration

If the public configuration is very simple, no multiple registry centers, no multiple protocols, etc., or if you want multiple Spring containers to share the configuration, you can use as the default configurations.

Dubbo would load under the classpath root directory automaticaly,you can change the default configuration location by JVM startup parameter Configuration example
# application name
# registry center address
# Example of broadcasting registry center
# address for calling protocol
Mapping Rule

Split the tag name and properties in XML configuration with dots, and multiple properties should be split into multiple lines

  • For example: equivalents to <dubbo:application name=“foo” />
  • For example: dubbo.registry.address= equivalents to <dubbo:registry address=“” />

If there are multiple configurations having the same tag name, they can be distinguished by id, and if there is no id, the configurations will be applied to all tags with the same name.

  • For example: dubbo.protocol.rmi.port=1234 equivalents to <dubbo:protocol id=“rmi” name=“rmi” port=“1234” />
  • For example: dubbo.registry.china.address= equivalents to <dubbo:registry id=“china” address=“” />
Coverage Strategy


  • When JVM starts, -D parameter has priority, so that users can rewrite the parameters when deploy and start, for example, the protocol port should be changed when start.
  • Then comes to XML, the configurations in are invalid, if they are configured in XML.
  • Properties are the last, which can be considered as default value. Only when there is no configuration in XML, the corresponding configuarations in will become effective, which usually applies to shared public configuration, like application name.


  1. If there are multiple in the classpath root directory, for example, if exist in multiple JAR files, Dubbo will load anyone arbitrarily and print the Error logs, which may change to throwing exceptions later.↩
  2. When the protocol’s id is not configured, protocol name will be used as id as default.


Service Annotation Exposure Service

@Service(timeout = 5000)
public class AnnotateServiceImpl implements AnnotateService { 
    // ...
Javaconfig Configuration Public Module
public class DubboConfiguration {

    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        return applicationConfig;

    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        return registryConfig;

The result of configuration using this method is the same as that of using xml.

Specify the Dubbo Scan Path
@DubboComponentScan(basePackages = "")
public class ProviderTestApp {
    // ...

or use the spring bean xml configuration:

<dubbo:annotation package="com.chanshuyi.service.impl" />

API Trigger Directly


// Service implementation
XxxService xxxService = new XxxServiceImpl();

// current application configuration
ApplicationConfig application = new ApplicationConfig();

// connect to registry center configuration
RegistryConfig registry = new RegistryConfig();

// service provider's protocol configuration
ProtocolConfig protocol = new ProtocolConfig();

// Note: ServiceConfig is a heavy object, which encapsulated the connection with registry center internally, and open the service port

// Service provider exposes service configuration
ServiceConfig<XxxService> service = new ServiceConfig<XxxService>(); // This instance is very heavy, which encapsulated the connection with registry center, please cache it by yourself, it might cause memory and connection leakage otherwise.
service.setRegistry(registry); // multiple registry centers can use setRegistries()
service.setProtocol(protocol); // multiple protocols can use setProtocols()

// exposure and register service

Generally, this method is not recommended in spring applications. The reason can be checked by reading the source code on github, which would not be explained here.

Provider Interface and Implement

The above chapters are described mainly from a configuration perspective, and lets explain the complete use of Dubbo provider by going through a complete example.

There is only one service UserReadService, and one method getUserById in this example. This service need to be exposed to a remote service by Dubbo. Detail steps are shown below:

  1. Create Project Skip this step if there is already a project. Create a Spring Boot project, which can be created through
  2. Define Interface Define interface: UserReadService
public interface UserReadService{
    public User getUserById(Long userId);

Generally, this interface should be placed in an independent JAR file as a client package. Generally, the other services need to refer this client package if they want to consume this service(except for generalized call). 3. Implement Interface Implement UserReadService, and deploy current implementation in the Provider’s application.

public UserReadServiceImpl implements UserReadService{
    public User getUserById(Long userId){
        return xxx;
  1. Dubbo Configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    <dubbo:application name="hello-world-app" />  
    <dubbo:registry address="multicast://" />  
    <dubbo:protocol name="dubbo" port="20880" />  
    <bean id="userReadService" class="com.package.UserReadServiceImpl"/>
    <dubbo:service interface="com.package.UserReadService" ref="userReadService" />  

For the other modes of Dubbo configuration, please refer to the related configurations in the previous chapter, or use the integrated Dubbo Spring Boot starter method.