Build the first spring boot project

I have been learning and using spring boot for a while, and now I will continue to summarize the relevant knowledge points in spring boot learning.

SpringBoot

The purpose of the design is to simplify the initial construction and development process of the new Spring application.
It provides a fixed framework of convention over configuration style for Spring ecosystem.
Out of the box, no code generation, no XML configuration required. You can also modify the default values to meet specific needs.

Environmental preparation

  1. jdk1.8+
  2. maven 3.0+
  3. IDEA

Construction steps

    -Open IDEA
    - New Project
    - Spring Initializr => next
    -Fill in group, artifact - > hook up Web (open web function)
    - next

engineering structure

    - src
        -main
            -java
                -package
                    -SpringbootApplication
            -resouces
                - statics
                - templates
                - application.yml
        -test
    - pom
  • pom file is the basic dependency management file
  • Resources file
    • Static resources
    • templates resources
    • application.yml configuration file
  • The entry of SpringbootApplication program & startup class

pom.xml configuration

<?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.forezp</groupId>
    <artifactId>springboot-first-application</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>springboot-first-application</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <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>
        <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>

Test Demo

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

/**
 *  test case
 *
 * @author botaogou@gmail.com
 * @create 2018-01-05 11:32
 **/

@RestController
public class DemoController {

    @RequestMapping("/hello")
    String index() {
        return "Hello World!";
    }
}

Then start the main method of SpringbootApplication, open the browser localhost:8080/hello, and the browser displays

Hello World!

Pass the test~

Tags: Java Spring Maven SpringBoot xml

Posted on Sun, 03 May 2020 22:43:06 -0400 by HockeyDevil07