The project architecture

  • Parent project: Globally manages the version numbers of all imported dependencies.
    • After the version number is configured in the parent project, all modules inherited from the parent project do not need to import the version number again.
  • Common modules: Globally manage common entity classes, common utility classes, and common dependencies.
    • After the entity class and tool class are configured in the common module, all modules that depend on the common module can be directly used by the guide package.
    • You do not need to import dependencies for all modules that depend on the common module.
  • Services: Manage their own unique dependencies to implement the corresponding business.

Note:

  1. Because You can’t introduce Web dependencies in a gateway service, you might need to introduce Web dependencies in all other services. So Web dependencies generally remain in the common module, but gateway services do not depend on the common module and only inherit from the parent project.

Build steps

1. Build the project folder

  1. Create a project folder under the local file directory

  2. IDEA select File –> Open to Open the project folder

2. Build the parent project

  1. Right click on the project folder: New –> Module –> Maven –> Next (do not need to select archetype)

  2. Configuring Module Parameters

  3. Delete the SRC directory from the parent project

  4. The pom.xml file template for the parent project

    
            
    <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>org.aydenbryan</groupId>
        <artifactId>covid-19-data-platform-parent</artifactId>
        <packaging>pom</packaging>
        <version>1.0 the SNAPSHOT</version>
        <! All modules inherited from the parent project will be automatically added -->
        <modules>
            <module>covid-19-data-platform-common</module>
            <module>covid-19-data-platform-reptile</module>
        </modules>
    
        <! -- Inherit from Spring Boot parent project -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.5. RELEASE</version>
        </parent>
    
        <! -- Version number of imported component -->
        <properties>
            <! -- public module version number -->
            <common.version>1.0 the SNAPSHOT</common.version>
            <java.version>1.8</java.version>
            <spring.cloud.version>Hoxton.SR6</spring.cloud.version>
        </properties>
    
        <! -- Import component declaration -->
        <dependencyManagement>
            <dependencies>
                <! -- Public module declaration -->
                <dependency>
                    <groupId>org.aydenbryan</groupId>
                    <artifactId>covid-19-data-platform-common</artifactId>
                    <version>${common.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring.cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>
    Copy the code

    Note:

    1. Dependencies and dependencyManagement differ in the following ways:
      • If the parent project uses Dependencies to configure the dependencies, the child project will inherit all the dependencies from the parent project even if it does not write the dependency in the child project.
      • If the parent project uses dependencyManagement to configure the dependency, it declares the dependency and does not introduce it. Therefore, subprojects need to separately configure the dependencies they need to use.

3. Build common modules

  1. Right-click on the project folder: New –> Module –> Maven –> Maven-archetype-quickstart –> Next

  2. Configuring Module Parameters

    Note: You need to inherit the common module from the parent project.

  3. Configuring Maven paths

  4. The pom.xml file template for the common module

     
            
     
     <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">
       <! -- Inherit the parent project -->
       <parent>
         <groupId>org.aydenbryan</groupId>
         <artifactId>covid-19-data-platform-parent</artifactId>
         <version>1.0 the SNAPSHOT</version>
       </parent>
       <modelVersion>4.0.0</modelVersion>
     
       <artifactId>covid-19-data-platform-common</artifactId>
     
       <name>covid-19-data-platform-common</name>
       <! -- FIXME change it to the project's website -->
       <url>http://www.example.com</url>
     
       <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <! -- Maven automatically resets the DEFAULT JDK version to 1.8 -->
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
       </properties>
     
       <! -- Configure public dependencies -->
       <dependencies>
         
       </dependencies>
     </project>
    Copy the code
  5. Delete the test directory and APP class from the common module

  6. Add entity, util package

Note:

  1. If the pom. XML of the module is gray and crossed out after the module is created, the solution is: Deselect it

  2. When selecting archetype, you are advised to select Maven-archetype-QuickStart. Maven-archetype-webapp is also a good choice, but now most projects are separated from the front end and the back end service should not include the front end page, so it doesn’t make sense to choose Maven-archetype-webapp.

4. Build service modules

  1. Create a service module the same way you create a common module (see top)

  2. The pom.xml file template for the service module

    
            
    
    <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">
      <! -- Inherit the parent project -->
      <parent>
        <groupId>org.aydenbryan</groupId>
        <artifactId>covid-19-data-platform-parent</artifactId>
        <version>1.0 the SNAPSHOT</version>
      </parent>
      <modelVersion>4.0.0</modelVersion>
    
      <artifactId>covid-19-data-platform-reptile</artifactId>
    
      <name>covid-19-data-platform-reptile</name>
      <! -- FIXME change it to the project's website -->
      <url>http://www.example.com</url>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
      </properties>
    
      <! -- Configure service unique dependencies -->
      <dependencies>
        <! -- Each service must rely on a common module -->
        <dependency>
          <groupId>org.aydenbryan</groupId>
          <artifactId>covid-19-data-platform-common</artifactId>
        </dependency>
      </dependencies>
    </project>
    Copy the code
  3. Delete the APP class and APPTest class

  4. Create a service module entry class

    @SpringBootApplication
    public class ReptileAppication {
    
        public static void main(String[] args) { SpringApplication.run(ReptlieApplication.class, args); }}Copy the code
  5. Create the resources directory and set it to Resources Root

  6. Create application.yml in the Resources directory

  7. The configuration application. Yml

    server:
      port: 9000
    
    spring:
      application:
        name: reptile
    Copy the code

Note:

  1. Every service module we build has no Spring Boot Boot class, so we need to write it ourselves.
  2. When two or more modules are running, IDEA will automatically bring up the Service Dashboard.