preface

Know ahead of time

There are several ways to build a Springboot project:

  1. Through the Spring official website tool start.spring. IO /
  2. Through the scaffolding of Idea
  3. Through Eclipse plug-ins
  4. Introduce dependencies through Maven

The common roughly these, not a introduction, personally prefer to create through Maven, this is also the content of this article.

Main Contents of this article

Development tools: Jetbrain Idea, Git

Development language: Java

Development platform: Windows

Desired goal: Manually build a Springboot project and run it successfully.

In actual combat

Develop detailed steps

1. Create a project directory

Create an empty folder and name it xiaoming- System, which is the name of our project.

2. Add the initial file

Add three initial files, which are:

The file name File meaning
pom.xml The Maven project configuration file, Idea will automatically identify it and create a Maven project
.gitignore Git repository, ignored files for code versioning
readme.md Description file of the project

The contents of the file are as follows:

1) pom. XML


      
<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>cc.xiaoming</groupId>
    <artifactId>xiaoming-system</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0</version>

    <! -- Parent dependencies of this project, specifying the various Springboot specifications -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.3</version>
        <relativePath/>
    </parent>

    <! -- attribute parameters -->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <! -- Various dependency frameworks -->
    <dependencies>
        <! -- SpringBoot Web Project startup dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>
Copy the code

(2) the gitignore

### IntelliJ IDEA ###
.idea
*.iml
Copy the code

(3) the readme, md

Project name: Xiao Ming's personal website
Copy the code

(4) The project directory

3. Initialize the repository

(1) In the root directory of the current project, initialize an empty repository: git init

Add the three initial files to the staging area of the repository: git Add.

Commit the three initial files to the repository: git commit -m “Initialize project files”

Later in the development process, remember to submit the code and fill in the submit information (describing what you changed).

4. Initialize the project

Using Idea to open the project directory xiaoming-system, it will automatically build a Maven project.

② You will find that there is an extra.idea folder and.iml file. Don’t worry about them for the time being. These are files generated automatically by idea, and please ignore them when submitting code to the repository.

(3) File -> Project Structure. Check the JDK version used by the Project. Many times when you open a project, Idea will automatically help you to select a version, not necessarily the version you want to use, to manually change, or run may report an error.

5. Build the Springboot project

In fact, it is still a Maven project, but it is easy to build a Springboot project. It is a Springboot project based on the Maven project, introduce Springboot dependencies, and then develop the business logic.

New module: Xiaoming -starter, which is the module where the program starts.

② At this time, there will be an extra module under the project.

(3) Pom.xml for xiaoming-starter


      
<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>
    <parent>
        <artifactId>xiaoming-system</artifactId>
        <groupId>cc.xiaoming</groupId>
        <version>1.0.0</version>
    </parent>

    <artifactId>xiaoming-starter</artifactId>

</project>
Copy the code

In this case, we added a new module to our pop.xml submodule:

<modules>
    <module>xiaoming-starter</module>
</modules>
Copy the code

⑤ Add the program startup class XMApplication.java, which will serve as an entry point to the entire program.

package cc.xiaoming;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/** * SpringBoot program boot class */
@SpringBootApplication
@RestController
public class XiaomingApplication {

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

    @RequestMapping("/hello")
    public String hello(a) {
        return "Hello, Welcome to xiaoming-system."; }}Copy the code

6. Run the program

Make sure all dependencies are imported before running:

② Enter the access interface in the browser address bar:

Obviously, the run is successful, the interface is accessible.

Now that the Springboot project is basically set up, we can continue to add the functionality we need.

Oh! Add the code to the repository, by the way.