Eclipse creates spring boot aggregation project

Eclipse creates spring boot aggregation project

1. Create parent project

1.1 create a Maven project

1.2 create a simple project

1.3 fill in basic information of the project

1.4 project directory structure

1.5 write pom.xml file information of 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">

    <!-- Project Description: as the parent project of aggregation project -->
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.qfx</groupId>
    <artifactId>parenteProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>parenteProject</name>
    <description>This is a Maven Parent project of aggregate project</description>

    <!-- Setting parent class,Integrate common third-party framework dependency information(Various dependent information),Inheritance here SpringBoot Parent project provided -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <!-- Set common parameters -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- 1.Introduce springboot Core package,integration SpringMVC Web assembly -->
        <!-- Implementation principle: Maven Dependent inheritance,It is equivalent to using the third party frequently Maven Dependent information,stay parent It's packaged in the project -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- 2. Introduce springboot Test package -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- 3. springboot external tomcat Support,For compilation jsp -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- 4. hit war Add this item when package, tell spring-boot tomcat Relevant jar It's all external. Don't type it in -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests><!--Turn unit tests off by default -->
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2. Create subproject

2.1 create a Maven subproject

2.2 fill in the name of subproject

2.3 select sub project prototype

2.4 fill in basic information

2.5 project directory structure

Note: if the child item is displayed horizontally with the parent item, you can perform the following operations, and switch the operation view

2.6 the pom.xml file of the parent project has referenced the child project, as shown in the figure:

2.7 write pom.xml file information of subproject

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

    <!-- Project Description: as a sub project of polymerization project -->
    <modelVersion>4.0.0</modelVersion>
    <artifactId>project-web</artifactId>
    <name>project-web</name>
    <!-- Packing method is war,Not written as default jar -->
    <packaging>war</packaging>

    <!-- Setting parent class,,Inheritance here parenteProject Parent project -->
    <parent>
        <groupId>com.qfx</groupId>
        <artifactId>parenteProject</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
</project>

2.8 modify the startup class org.project.web.App.java of the Spingboot subproject

package org.project.web;

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

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

2.9 add a test class org.project.web.controller.TestController.java

package org.project.web.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("test")
public class TestController {

    @RequestMapping("sayHello")
    public String sayHello() {
        return "How do you do~!";
    }
}

2.10 start Springboot

2.11 testing, http://127.0.0.1:8080/test/sayHello

EclipseSpringboot

3. Repeat step 2 to create multiple subprojects

Tags: Java Maven Apache Spring SpringBoot

Posted on Sat, 02 Nov 2019 13:11:23 -0700 by project168