All Products
Search
Document Center

Enterprise Distributed Application Service:Implement service registration and discovery

Last Updated:Mar 11, 2026

Enterprise Distributed Application Service (EDAS) provides the general availability (GA) version of the Nacos registry. Spring Cloud applications built with Nacos can connect to this shared registry without code modification -- deploy to EDAS, and the platform handles registry connectivity automatically.

This tutorial walks through building two Spring Cloud microservices -- a service provider and a service consumer -- that register with Nacos for service discovery. By the end, you will have:

  1. A local Nacos Server running in standalone mode.

  2. A service provider that registers with Nacos and exposes a REST endpoint.

  3. A service consumer that discovers the provider through both RestTemplate and FeignClient.

  4. End-to-end service discovery verified locally.

After local verification, deploy both applications to EDAS. See Deploy applications to ECS instances or Deploy applications to Kubernetes clusters.

Note

EDAS supports multiple registries, including Nacos, Eureka, ZooKeeper, and Consul (self-managed or through Microservice Engine (MSE)). Regardless of which registry you use, EDAS provides application management, microservice governance, and cloud-native PaaS capabilities after deployment.

Prerequisites

Before you begin, make sure that you have:

  • Maven installed and environment variables configured

  • The latest Nacos Server downloaded and extracted

Start Nacos Server

  1. Navigate to the nacos/bin directory.

  2. Start Nacos Server in standalone mode:

    • Linux, UNIX, or macOS:

      sudo sh startup.sh -m standalone
    • Windows: double-click startup.cmd.

  3. Open http://127.0.0.1:8848/nacos in your browser to verify that Nacos Server is running. The default username and password are both nacos.

Project structure

This tutorial creates two independent Maven projects:

nacos-service-provider/
├── pom.xml
└── src/main/
    ├── java/com/aliware/edas/
    │   ├── ProviderApplication.java
    │   └── EchoController.java
    └── resources/
        └── application.properties

nacos-service-consumer/
├── pom.xml
└── src/main/
    ├── java/com/aliware/edas/
    │   ├── ConsumerApplication.java
    │   ├── EchoService.java
    │   └── TestController.java
    └── resources/
        └── application.properties

Download the complete demo projects: service-provider | service-consumer.

Create the service provider

Step 1: Set up the Maven project

Create a Maven project named nacos-service-provider and add the following dependencies to pom.xml. This example uses Spring Boot 2.1.4.RELEASE and Spring Cloud Greenwich.SR1:

Expand to view the code

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
    <relativePath/>
</parent>

<dependencies>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        <version>2.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Greenwich.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The Spring Cloud Alibaba version must match your Spring Cloud release:

Spring Cloud releaseSpring Cloud Alibaba version
Greenwich2.1.1.RELEASE
Finchley2.0.1.RELEASE
Edgware1.5.1.RELEASE
Note

Spring Cloud Edgware has reached end of life. Do not use Edgware for new projects.

Step 2: Create the application class

In src/main/java, create the package com.aliware.edas, then add ProviderApplication.java:

package com.aliware.edas;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient  // Enables service registration and discovery
public class ProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }
}

Step 3: Add a REST controller

In the same package, create EchoController.java to expose a /echo/{string} endpoint:

package com.aliware.edas;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EchoController {
    @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
    public String echo(@PathVariable String string) {
        return string;
    }
}

Step 4: Configure the registry address

In src/main/resources, create application.properties:

spring.application.name=service-provider
server.port=18081
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848

Replace 127.0.0.1 with the IP address of your Nacos Server if it runs on a different machine. For additional configuration options, see Configuration reference.

Step 5: Verify registration

  1. Run the main method of ProviderApplication to start the service.

  2. Open the Nacos console at http://127.0.0.1:8848/nacos (username/password: nacos/nacos).

  3. Go to Service Management > Services. service-provider appears in the service list. Click Details to view registration details such as the instance IP and port.

Create the service consumer

The consumer demonstrates two approaches for calling the provider: RestTemplate with client-side load balancing, and FeignClient as a declarative HTTP client.

Step 1: Set up the Maven project

Create a Maven project named nacos-service-consumer and add the following dependencies to pom.xml:

Expand to view the code

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
    <relativePath/>
</parent>

<dependencies>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        <version>2.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Greenwich.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Step 2: Define the Feign client interface

In src/main/java, create the package com.aliware.edas, then add EchoService.java:

package com.aliware.edas;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(name = "service-provider")  // Refers to the provider's registered service name
public interface EchoService {
    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    String echo(@PathVariable("str") String str);
}

Step 3: Create the application class

In the same package, create ConsumerApplication.java:

package com.aliware.edas;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient   // Enables service registration and discovery
@EnableFeignClients      // Activates FeignClient scanning
public class ConsumerApplication {

    @LoadBalanced  // Integrates RestTemplate with service discovery for client-side load balancing
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }
}

Annotation summary:

  • @EnableDiscoveryClient -- registers this application with Nacos.

  • @EnableFeignClients -- scans for @FeignClient interfaces and creates proxy beans.

  • @LoadBalanced -- enables RestTemplate to resolve service names (such as service-provider) through the registry instead of DNS.

Step 4: Add a test controller

In the same package, create TestController.java with two endpoints that call the provider using different approaches:

package com.aliware.edas;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private EchoService echoService;

    // Uses RestTemplate with service discovery to call the provider
    @RequestMapping(value = "/echo-rest/{str}", method = RequestMethod.GET)
    public String rest(@PathVariable String str) {
        return restTemplate.getForObject("http://service-provider/echo/" + str,
                String.class);
    }

    // Uses FeignClient to call the provider
    @RequestMapping(value = "/echo-feign/{str}", method = RequestMethod.GET)
    public String feign(@PathVariable String str) {
        return echoService.echo(str);
    }
}

Step 5: Configure the registry address

In src/main/resources, create application.properties:

spring.application.name=service-consumer
server.port=18082
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848

Replace 127.0.0.1 with the IP address of your Nacos Server if it runs on a different machine.

Step 6: Verify registration

  1. Run the main method of ConsumerApplication to start the service.

  2. Open the Nacos console at http://127.0.0.1:8848/nacos.

  3. Go to Service Management > Services. service-consumer appears in the service list alongside service-provider.

Test service discovery locally

With both applications running, test end-to-end service discovery. The consumer resolves the service name service-provider through Nacos and forwards each request to the provider.

Linux, UNIX, or macOS:

# Test with RestTemplate
curl http://127.0.0.1:18082/echo-rest/rest-rest

# Test with FeignClient
curl http://127.0.0.1:18082/echo-feign/feign-rest

Windows: Open the following URLs in your browser:

  • http://127.0.0.1:18082/echo-rest/rest-rest

  • http://127.0.0.1:18082/echo-feign/feign-rest

Expected output:

EndpointExpected response
/echo-rest/rest-restrest-rest
/echo-feign/feign-restfeign-rest

If both endpoints return the path parameter value, service registration and discovery are working correctly.

Deploy to EDAS

After local verification, deploy both applications to EDAS. EDAS provides a managed Nacos registry, so your applications connect to it automatically without code modification.

For deployment instructions, see:

Configuration reference

Nacos Discovery supports the following configuration properties in application.properties:

Configuration itemKeyDefault valueDescription
Server addressspring.cloud.nacos.discovery.server-addrNoneIP address and port of the Nacos Server
Service namespring.cloud.nacos.discovery.service${spring.application.name}Name used to register the service
NIC namespring.cloud.nacos.discovery.network-interfaceNoneNetwork interface whose IP address is registered. Defaults to the first NIC if unspecified
Registered IP addressspring.cloud.nacos.discovery.ipNoneOverrides the auto-detected IP. Takes highest priority
Registered portspring.cloud.nacos.discovery.port-1Auto-detected by default
Namespacespring.cloud.nacos.discovery.namespaceNoneIsolates services across environments (for example, dev, staging, production)
Metadataspring.cloud.nacos.discovery.metadataNoneCustom key-value pairs attached to the service instance. Configured in Map format
Clusterspring.cloud.nacos.discovery.cluster-nameDEFAULTNacos cluster name
Endpointspring.cloud.nacos.discovery.endpointUTF-8Domain name for dynamic server address resolution. Not required when deployed to EDAS
Ribbon integrationribbon.nacos.enabledtrueEnables Ribbon-based load balancing with Nacos. Change only when necessary

For the complete reference, see Nacos Discovery on GitHub.