This topic walks you through building a sample Dubbo microservice application locally with XML configuration and deploying it to Serverless App Engine (SAE). The application consists of a service provider and a service consumer, both using Nacos as the service registry. After deployment, SAE automatically replaces the local Nacos registry address—no configuration changes are required.
Prerequisites
Before you begin, make sure you have:
Maven installed and configured in your environment variables
A local Nacos Server running in standalone mode (see the steps below)
Set up Nacos Server
Download and decompress the Nacos Server package.
Go to the
nacos/bindirectory and start Nacos Server:Linux, Unix, or macOS: ``
bash sudo sh startup.sh -m standalone``Windows: ``
bash startup.cmd -m standalone``
standalonestarts Nacos in standalone mode instead of cluster mode. If double-clickingstartup.cmdon Windows fails, open the file and setMODE="standalone"manually. For details, see Quick Start for Nacos.
Version note: Dubbo 2.7.x and Dubbo 3.0.x reached end of life in March 2023. This topic uses Dubbo 3.2.15.
Step 1: Create a provider
Create a Maven project locally, define the service interface, configure XML-based service registration, and start the provider.
1.1 Create a Maven project and add dependencies
Use an IDE (such as IntelliJ IDEA or Eclipse) to create a Maven project.
Add the following dependencies to
pom.xml:<dependencies> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>3.2.15</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-registry-nacos</artifactId> <version>3.2.15</version> </dependency> <dependency> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> <version>1.1.1</version> </dependency> </dependencies>
1.2 Define the service interface
All Dubbo services are defined through interfaces.
In
src/main/java, create the packagecom.alibaba.edas.In
com.alibaba.edas, create theIHelloServiceinterface:package com.alibaba.edas; public interface IHelloService { String sayHello(String str); }In
com.alibaba.edas, create theIHelloServiceImplimplementation class:package com.alibaba.edas; public class IHelloServiceImpl implements IHelloService { public String sayHello(String str) { return "hello " + str; } }
1.3 Configure the Dubbo service
In
src/main/resources, createprovider.xml.Add the Spring and Dubbo XML namespaces:
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">Expose the service interface and point to the local Nacos Server:
Item Value Note Registry address nacos://127.0.0.1:8848Points to your local Nacos Server. After deploying to SAE, this address is automatically replaced with the SAE-managed registry—no code change needed. Nacos port 8848Fixed; do not change. <dubbo:application name="demo-provider"/> <dubbo:protocol name="dubbo" port="28082"/> <dubbo:service interface="com.alibaba.edas.IHelloService" ref="helloService"/> <bean id="helloService" class="com.alibaba.edas.IHelloServiceImpl"/> <dubbo:registry address="nacos://127.0.0.1:8848" />Key configuration:
1.4 Start the provider
In
com.alibaba.edas, create theProviderclass:package com.alibaba.edas; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Provider { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"}); context.start(); System.in.read(); } }Run the
Providermain method to start the service.
Verify the provider
Log on to the Nacos console at http://127.0.0.1:8848. In the left navigation pane, click Service List.
The service com.alibaba.edas.IHelloService appears in the list, along with its Service Group and Provider IP.
Step 2: Create a consumer
Create a separate Maven project for the consumer, subscribe to the provider service, and verify the call works locally.
2.1 Create a Maven project and add dependencies
Follow the same steps as Step 1.1 to create a Maven project and add the same three dependencies to pom.xml.
2.2 Define the service interface
In
src/main/java, create the packagecom.alibaba.edas.In
com.alibaba.edas, create the sameIHelloServiceinterface:package com.alibaba.edas; public interface IHelloService { String sayHello(String str); }
In production, define the interface in a shared module and reference it from both the provider and consumer via Maven dependencies. Duplicating the interface here is for demonstration only.
2.3 Configure the Dubbo service
In
src/main/resources, createconsumer.xml.Add the Spring and Dubbo XML namespaces (same as
provider.xml):<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">Subscribe to the provider service:
<dubbo:application name="demo-consumer"/> <dubbo:registry address="nacos://127.0.0.1:8848"/> <dubbo:reference id="helloService" interface="com.alibaba.edas.IHelloService"/>
2.4 Start the consumer
In
com.alibaba.edas, create theConsumerclass:package com.alibaba.edas; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.concurrent.TimeUnit; public class Consumer { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"consumer.xml"}); context.start(); while (true) { try { TimeUnit.SECONDS.sleep(5); IHelloService demoService = (IHelloService)context.getBean("helloService"); String result = demoService.sayHello("world"); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } } } }Run the
Consumermain method to start the service.
Verify the consumer
After startup, the console continuously prints:
hello worldThis output confirms the consumer is successfully calling the provider.
Log on to the Nacos console at http://127.0.0.1:8848 and click Services in the left navigation pane. Select Callers.
The service com.alibaba.edas.IHelloService appears in the list, along with its Service Group and Subscriber IP.
Step 3: Deploy to SAE
Package the provider and consumer as executable JAR files, then deploy them to SAE.
3.1 Add the build plugin
Add the following <build> configuration to the pom.xml of each project:
Provider — set
mainClasstocom.alibaba.sae.Provider:<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>spring-boot</classifier> <mainClass>com.alibaba.sae.Provider</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build>Consumer — set
mainClasstocom.alibaba.sae.Consumer:<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>spring-boot</classifier> <mainClass>com.alibaba.sae.Consumer</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build>
3.2 Build the JAR packages
In each project directory, run:
mvn clean packageThis produces an executable JAR in the target/ directory.
3.3 Deploy to SAE
Deploy both JAR packages to SAE. For deployment steps, see Deploy a Java application.
After deployment, SAE automatically replaces the local Nacos registry address (nacos://127.0.0.1:8848) with the address of the SAE-managed service registry. No changes to your configuration files are needed.What's next
Deploy a Java application — full deployment options for JAR-based applications on SAE