How to use the creation of Nacos and gateway center in Java Spring Cloud practice? 80% won't

Posted by dyip on Thu, 04 Jun 2020 07:55:37 +0200


0. Preface

In the previous section, we created a project architecture, which will be supplemented by subsequent projects.

1. Nacos


Nacos can be used to discover, configure, and manage microservices. It provides a set of simple and easy-to-use feature sets, which can quickly realize dynamic service discovery, service configuration, service metadata and traffic management.

Nacos is used to build, deliver, and manage microservice platforms more quickly and easily. Nacos is the service infrastructure for building a "service" centered modern application architecture (such as micro service paradigm and cloud native paradigm).

That is to say, the configuration center and service discovery center.

Note: light theory is not enough. In this free gift of 5 JAVA architecture project practical course and large factory interview question bank, interested can get into skirt 783802103, do not enter without foundation!
1.2 build and start up

The current version of Nacos does not support the creation of services in the form of Spring boot. It must be run in the form of a Java package alone or in the form of a Docker service. Let's talk about local running.

Download the installation package:

unzip nacos-server-$ perhaps tar -xvf nacos-server-$version.tar.gz
cd nacos/bin

Install using source code:

git clone
cd nacos/
mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U  
ls -al distribution/target/

// change the $version to your actual path
cd distribution/target/nacos-server-$version/nacos/bin



Start command (standalone stands for stand-alone mode operation, non cluster mode):

sh -m standalone

If you are using the ubuntu system, or running the script with an error message [[the symbol cannot be found, try running as follows:

bash -m standalone


Start command:

cmd startup.cmd

Or double click startup.cmd Run the file.

2. Spring Cloud Gateway

For the whole gateway service, we adopt Spring Cloud Gateway. In Spring Cloud microservices, the whole system only exposes the gateway to the outside world, and other services are invisible to the outside world. So we need to set up a gateway service that we can use.

Create a gateway directory under nature/manager and add pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""



Register the module under manager:


2.1 add Gateway

After creating the project, you need to add a dependency package:

<!-- -->

In the gateway project, create the following directory:

├── pom.xml
└── src
    └── main
        ├── java
        │   └── club
        │       └── attachie
        │           └── gateway
        │               └──
        └── resources
            └── bootstrap.yml

establish File, code as follows:

package club.attachie.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

 * @author attaching
public class SpringGatewayApplication {
    public static void main(String[] args) {, args);

Create in resource directory bootstrap.yml :

    name: gateway

yml is a configuration file format of Spring. Its name includes application and bootstrap. Bootstrap loads before application.

2.2 add nacos

First in nature/pom.xml Add nacos version number:


Then add nacos related dependency management under dependency Management > dependencies:


In the Gateway project pom.xml add to:


Then turn around and set in bootstrap:

    name: gateway


3 Summary

So far, the configuration of nacos and the introduction of Gateway application have been introduced. Because individuals have not conducted too much in-depth research on related technologies, so they can only do so at present. The follow-up research is in-depth and will be supplemented in this series.
Finally note: the theory of light is not enough. In this free gift of 5 JAVA architecture project practical course and large factory interview question bank, interested can get into skirt 783802103, do not enter without foundation!

The text and pictures of this article come from the Internet and my own ideas. They are only for learning and communication. They have no commercial use. The copyright belongs to the original author. If you have any questions, please contact us in time for handling

Topics: Java Spring xml Maven