Manually create a springboot project based on idea

Time:2021-8-29

Create Maven project

Manually create a springboot project based on idea

Specify project name

Manually create a springboot project based on idea

Edit pom.xml configuration 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.jt</groupId>
    <artifactId>springboot_demo2</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!-- 1. Uniformly define parent items -- >
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <!-- Skip test class loading -- >
        <skipTests>true</skipTests>
    </properties>

    <!-- 2. Introduce third-party dependency -- >
    <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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>


    <!-- 3. Add plug-in -- >
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Edit main startup class

@Springbootapplication // identifies that I am a springboot project
public class SpringBootRun {

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

}

Edit test controller

package com.jt.controller;

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

@RestController
public class HelloController {

    /**
     *The user obtains friendly prompt information through the path of / Hello
     */
    @RequestMapping("/hello")
    public String hello(){

        Return "it's really difficult to build an environment. Why can't I do it? What did I do yesterday;
    }
}

Recommended Today

As package jar and AAR

Jar packaging (only class files and manifest files are included, not resource files, such as pictures and all files in Res) 1. Create a new project in as and a new model module. Add the model dependency to build. Gradle in the project, and then compile the project. Then add the following configuration in build.gradle […]