First day of learning SpringBoot

First day of learning SpringBoot

1. What is SpringBoot

Spring boot is designed based on spring 4.0. It not only inherits the original excellent features of spring framework, but also further simplifies the whole construction and development process of spring application by simplifying configuration. In addition, SpringBoot integrates a large number of frameworks to solve the version conflict of dependent packages and the instability of references.

Key benefits of SpringBoot

  • Get started faster for all Spring developers
  • Out of the box, various default configurations are provided to simplify project configuration
  • Inline containers simplify Web projects
  • There are no requirements for redundant code generation and XML configuration

2. The first SpringBoot program

2.1 environmental preparation

  • jdk1.8

  • Maven-3.6.1

  • The latest version of SpringBoot

  • IDEA

2.2 create basic project description

Spring Initializr:

Project creation method 1:

  1. open

  2. Fill in project information

  3. Click the "Generate Project" button to generate the project; download the project

  4. Unzip the project package and import it as Maven project with IDEA. Go to the next step until the project is imported.

Project creation method 2:

  1. Create a new project
  2. Select spring initalizr, and you can see that the default is to implement it in the quick build tool on the official website
  3. Fill in project information
  4. Select the initialized component (just check Web for beginners)
  5. Fill in the project path
  6. Wait for the project to build successfully

Project structure analysis:

  1. Main startup class of the program

  2. An configuration file

  3. A test class

  4. A pom.xml

3.pom.xml analysis


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
        <relativePath/> <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot</description>




There are four main parts:

  • Project Metadata: the Project Metadata entered during creation, that is, the basic elements of Maven project, including groupId, artifactId, version, name, description, etc

  • Parent: inherits the dependency management of spring boot starter parent, version control and packaging

  • Dependencies: project specific dependencies. Spring boot starter Web is used to implement the HTTP interface (Spring MVC is included in the dependency). The official website describes it as: using Spring MVC to build the Web (including RESTful) As the entrant to the application, Tomcat is used as the default embedded container. Spring boot starter test is used to write the dependency package of unit test. The use of more functional modules will be gradually expanded later.

  • Build: build the configuration part. Spring Boot Maven plugin is used by default. In combination with Spring Boot starter parent, Spring Boot applications can be packaged into jars to run directly.

4. Write an http interface

  1. Create a new controller package in the same level directory of the main program

  1. Create a new HelloController class in the package
public class HelloController {
    public String hello(){
        return "hello";
  1. After writing, start the project from the main program, the browser initiates a request, and look at the page to return; the console outputs the port number accessed by Tomcat!

5. Special notes

5.1 changing the port number

5.2 change the alphabet of the characters displayed at startup

Just one step: create a new banner.txt in the resources directory under the project.
Patterns can be to: This website is generated, and then copied to the file!

6. Parent dependency


  • Spring boot dependencies: the core depends on the parent project!
  • When we write or introduce some Springboot dependencies, we do not need to specify the version, just because there are these version repositories
  1. It mainly depends on a parent project, which mainly manages the resource filtering and plug-ins of the project!
        <relativePath/> <!-- lookup parent from repository -->
  1. Click in, and there is a parent dependency
  1. This is the place to really manage all dependent versions in the SpringBoot application, the SpringBoot version control center;

7. Spring boot starter

  • rely on
  • Springboot boot starter XXX is the springboot startup scenario

  • For example, spring boot starter web will help us automatically import all web dependencies

  • springboot will turn all functional scenarios into initiators one by one

  • If we want to use any function, we just need to find the corresponding initiator

8. Main program

8.1 default main startup program

package com.zhang;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//@Spring bootapplication to annotate a main program class
//This is a Spring Boot application
public class Springboot01HelloworldApplication {

    public static void main(String[] args) {, args);


8.2 annotation (@ SpringBootApplication)

  • Function: mark on a class to indicate that this class is the main configuration of SpringBoot
  • SpringBoot should run the main method of this class to start the SpringBoot application;
  • Enter this annotation: you can see that there are many other annotations above!
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}


  • This annotation is important in Spring and corresponds to the elements in the XML configuration.

  • Function: automatically scan and load qualified components or beans, and load the bean definition into the IOC container


Function: the configuration class of SpringBoot is marked on a class to indicate that it is a SpringBoot configuration class;


Turn on the auto configuration function

  • Previously, we needed to configure things ourselves, but now SpringBoot can automatically configure them for us;
  • @EnableAutoConfiguration tells SpringBoot to enable the auto configuration function so that the auto configuration can take effect;

Tags: Java Spring Spring Boot

Posted on Tue, 28 Sep 2021 14:48:05 -0400 by bubbasheeko