Setting Up and Configuring Nacos for Service Registration

Downloading and Starting Nacos

Begin by downloading the Nacos server package from the official GitHub repository:

https://github.com/alibaba/nacos/releases/tag/2.1.0

Extract the downloaded archive and execute the startup script. This initiates the Nacos server in standalone mode.

Spring Boot Project Configuration

In your Spring Boot parent project, include the following dependency management entries:

<!-- Spring Cloud Dependencies -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>${spring-cloud.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

<!-- Spring Cloud Alibaba Dependencies (Includes Nacos) -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2.2.8.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

For individual microservices that require Nacos registration, add this dependency:

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

Application Configuration

Configure your application properties to connect to the Nacos server:

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        username: nacos
        password: nacos

Annotate your main application class with @EnableDiscoveryClient and start the application. Successfully registered services will appear in the Nacos console.

Troubleshooting Common Issues

Service Registration Failures

If services don't appear in the Nacos console:

  • Verify compatibility between Spring Boot, Nacos, and Spring Cloud Alibaba versions using the official compatibility matrix
  • Check for configuration errors, particularly regarding namespaces if they're specified in your configuration

Nacos Server Startup Problems

  • Port conflicts: Modify the port setting in conf/application.properties or terminate the process using the port
  • Database configuration: For persistent storage, create a local database named 'nacos' and import the SQL schema from conf/nacos-mysql.sql. Update the database configuration in the properties file
  • Cluster configuration: Rename cluster.conf.example to cluster.conf and update IP addresses to match your local environment

Tags: Nacos Service Discovery Spring Cloud microservices configuration

Posted on Mon, 12 Oct 2026 16:07:10 +0000 by johanlundin88