How to build a SpringBoot Web project through idea (most basic version)

Build a SpringBoot Web project through idea


Article Directory

  • Build a SpringBoot Web project through idea
    1. Open idea and find create new project
    1. Creation method
    1. Configure project dependencies
    1. Create a new project module
    1. Summary

1. Open idea and find create new project

  1. Method 1
    idea creation project 1
  2. Method 2

idea creation project 2

2. Creation method

  1. New Project

Select Spring Initializr -> Project Sdk -> Next

Insert image description here

  1. Configuration Project

After clicking next in the first step, as shown below, the most important thing is type. You need to select Maven and based on the project. Do not create pom.xml. Then the jdk can be adjusted or not. It mainly depends on what jdk package you have. There are also things like adjusting the package name. These can be adjusted later depending on personal needs. Finally click Next.
Configuration project information
3. Project dependency configuration

After clicking Next in the second step, at this step, you can directly select Next and import any subsequent dependencies through the pom file.
Project dependency configuration
4. Project path configuration

Finally configure the path of the project, click Next

Project path configuration

3. Configure project dependencies

The pom.xml file of the new project is as follows:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.jzs</groupId>
    <artifactId>log</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>log-demo1</name>
    <description>single demo about log</description>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project> 
  1. The corresponding relationship with the project configuration steps is shown in the figure below, which is a part that can be modified.
    Project configuration correspondence diagram
  2. There are currently only two dependencies in the pom file, one is to provide web project service support, and the other is related to unit testing, as shown in the following two figures.
    Web service dependency

Unit test dependency

4. Create a new project module

  1. The project can also be divided into modules. The project module is actually a new project, but it has a parent-child project relationship. The new project is roughly as follows: Select the project->right-click->New->Module, and then the rest is the same as creating a new project

New project module

  1. You can add submodules in the tag, and specify the parent project in the tag. After specifying the parent project, you can inherit the dependencies configured in the parent project.
  2. Parent project pom file
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.jz</groupId>
    <artifactId>all-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>all-demo</name>
    <description>Demo project for Spring Boot</description>
    <modules>
        <module>module1</module>
        <module>module2</module>
    </modules>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project> 
  1. Subproject pom file
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.jz</groupId>
        <artifactId>all-demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>com.jz</groupId>
    <artifactId>all-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>all-demo-module1</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project> 

5. Summary

The above is a simple project framework for creating Java through idea. Distributed projects are only based on the above process, and then the required dependencies and related configurations are added to the dependency configuration. It is essentially the same creation method.