preface

Before writing this series of articles, I feel it’s important to explain what Spring Cloud is. Unlike Spring (The Spring Framework), it can be loosely understood as a container for managing beans. Nor is SpringBoot, which can be interpreted as an enhanced version of Spring, integrating SSM and other frameworks, with extensive support and recommendation for annotation development.

But for Spring Cloud, it is a microservices architecture framework, not a single project, but an integration of multiple projects. In other words, if you want to learn about Spring Cloud, you are actually learning about multiple microservices projects.

The so-called micro service is to split the original one-stop solution of the business into a specific module, each module only do one thing, and then incidentally derived from the unified management of these services module, as well as service protection measures and other modules. It boils down to five cores, service discovery (registration), load balancing, circuit breakers, service gateways, and distributed configuration.

How to create a Module

A few weeks ago, WHEN I wanted to build a module, I would have chosen Spring Initializer, but these days I feel more comfortable creating a new module directly. Everyone’s habits are different, how comfortable they are.

How to create a Module using Maven

By changing the module name, you can create the desired module. The advantage is that you can integrate the dependencies imported from the parent module, which is much easier than Spring Initializer, which requires manually configuring the module’s parent-child relationship (or you can leave a message if you know how).

preparation

In order to learn better, I first established a general project, also using Maven to establish a project, after the establishment of the structure is shown below

The next thing you need to do is delete the entire SRC directory, because you won’t need it later. The second is to modify the POM file


      
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.cutey.none</groupId>			
    <artifactId>springcloud-demo</artifactId>
    <packaging>pom</packaging>
    <version>1.0 the SNAPSHOT</version>


    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.3.0. RELEASE</version>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <! - spring boot 2.3.0 -- -- >
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.3.0. RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <! --spring cloud Hoxton.SR11-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR11</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>
Copy the code

GroupId and artifactId need to be modified in lines 7 and 8. The required dependencies can then be declared in the root module, in the POM file. For example, spring-boot-starter-Web above has entire dependencies in all submodules.

Even if you are lazy enough, you can write all the dependencies in the parent module, so that you can leave the POM files out of the way when you build the children.