3

Preface

Recently started to learn the new version of SpringCloud 2020.0.2, ready to use a brand-new architecture, as shown in the figure
image.png
So record the use of idea to create a multi-module project, and record the construction process step by step

Create Project (New Project)

image.png
image.png
image.png
image.png
image.png

New Module

image.png
image.png
image.png
image.png

Refer to SpringCloud pre-operation

1. Delete the src directory under the ztosin-parent project
image.png
2. Modify the pom.xml of the ztosin-parent project

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <artifactId>ztosin-nacossvr</artifactId>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
    </parent>
    
  <properties>
       <java.version>1.8</java.version>
       <spring-boot.version>2.4.4</spring-boot.version>
       <spring-cloud.version>2020.0.2</spring-cloud.version>
       <spring-cloud-alibaba.version>2020.0.RC1</spring-cloud-alibaba.version>
   </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
       <dependencies>
           <!-- spring boot 依赖 -->
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-dependencies</artifactId>
               <version>${spring-boot.version}</version>
               <type>pom</type>
               <scope>import</scope>
           </dependency>
           <!-- spring cloud 依赖 -->
           <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 依赖 -->
           <dependency>
               <groupId>com.alibaba.cloud</groupId>
               <artifactId>spring-cloud-alibaba-dependencies</artifactId>
               <version>${spring-cloud-alibaba.version}</version>
               <type>pom</type>
               <scope>import</scope>
           </dependency>
       </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.10</version>
                <configuration>
                    <dockerfile>src/main/docker/Dockerfile</dockerfile>
                    <!--                    <repository>spotify/foobar</repository>-->
                    <!--<tag>${project.version}</tag>-->
                    <buildArgs>
                        <!--提供参数向Dockerfile传递-->
                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

3. Add NacosServerApplication.java

package com.ztosin.nacossvr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

The final directory structure is as follows:
image.png

reference

Fang Zhipeng SpringCloud Blog
spring-cloud
Use IDEA to create a multi-module project


Awbeci
3.1k 声望213 粉丝

Awbeci