search
HomeJavajavaTutorialWhat are the basic operations and concepts of getting started with SpringBoot?

    1. What is Spring Boot

    Why should you learn Spring Boot?

    Spring was born to simplify the development of Java programs, and Spring Boot was born to simplify the development of Spring programs.

    Spring Boot is the scaffolding of the Spring framework. It was born for the rapid development of the Spring framework.

    2. Spring Boot Advantages

    • Quickly integrates frameworks. Spring Boot provides the function of starting to add dependencies, which is used to integrate various frameworks in seconds.

    • Built-in running container, no need to configure Web containers such as Tomcat, run and deploy programs directly.

    • Rapidly deploy projects to get your projects up and running without the need for external containers.

    • You can completely abandon the cumbersome XML and use annotations and configuration for development.

    • Supports more monitoring indicators to better understand the running status of the project.

    3.Spring Boot project creation

    • Create using Idea [provided by ide developer]

    • Web version creation method [Officially provided by Spring]

    ##3.1 Create using Idea

    The IDEA version is 2021.2.2

    What are the basic operations and concepts of getting started with SpringBoot?

    Because of our Idea community version (other versions are also applicable), you must first install the Spring Assistant (Spring Assistant) plug-in before you can create a Spring Boot project, as shown in the following figure:

    What are the basic operations and concepts of getting started with SpringBoot?

    What are the basic operations and concepts of getting started with SpringBoot?

    After installation, there is a Spring Assistant option, as shown in the figure below:

    What are the basic operations and concepts of getting started with SpringBoot?

    3.2 Spring Boot project

    What are the basic operations and concepts of getting started with SpringBoot?

    What are the basic operations and concepts of getting started with SpringBoot?

    https://start.aliyun.com

    What are the basic operations and concepts of getting started with SpringBoot?

    What are the basic operations and concepts of getting started with SpringBoot?

    What are the basic operations and concepts of getting started with SpringBoot?

    Click Finish to complete the Spring Boot project creation.

    Note:

    It takes a long time to load the Spring Boot item for the first time, because the current Spring Boot framework is not in its own local warehouse.

    In order to speed up the download of the Spring Boot project, before opening the project, please confirm that Maven has been configured as a domestic source

    3.3 Start and verify whether the Spring Boot project has been created successfully

    What are the basic operations and concepts of getting started with SpringBoot?

    What are the basic operations and concepts of getting started with SpringBoot?

    3.4 Web version creation (understanding)

    You can also create a Spring Boot project without using Idea. We can use the official version provided by Spring Web version to create a Spring Boot project.

    To create a project for the web version, first visit: https://start.spring.io, as shown in the figure below:

    What are the basic operations and concepts of getting started with SpringBoot?

    What are the basic operations and concepts of getting started with SpringBoot?

    Click the Generate button to download a Spring Boot zip package. After unzipping the zip, the directory is as follows:

    What are the basic operations and concepts of getting started with SpringBoot?

    After opening it with Idea, the Spring Boot item will be created successfully. As shown in the figure below:

    What are the basic operations and concepts of getting started with SpringBoot?

    4. Project directory introduction and application

    What are the basic operations and concepts of getting started with SpringBoot?

    The newly created Spring Boot project directory is as follows:

    What are the basic operations and concepts of getting started with SpringBoot?

    The Spring Boot project has two main directories:

    src/main/java is the Java source code.

    src/main/resources is static resources or configuration files:

    /static: static resource folder;

    /templates: template resource folder.

    4.1 Project operation

    Click the main method of the startup class to run the Spring Boot project. The successful startup is as shown in the following figure:

    What are the basic operations and concepts of getting started with SpringBoot?

    4.2 Output Hello world

    We learn JavaEE to implement Web projects or interfaces. Before, Spring was actually an ordinary Java project, and there was no way to interact directly with the browser, so next we have to use Spring Boot is used to interact with browsers and users.

    Create the HelloController file under the created project package path. The implementation code is as follows:

    package com.example.demo;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    @Controller
    @RequestMapping("/hi")//路由映射
    public class HelloController {
        @RequestMapping("/index")//路由映射
        @ResponseBody//返回一个非静态页面的数据
        public String sayHi(){
            return "你好,Spring Boot";
        }
    }

    Restart the project and visit http://localhost:8080/hi/index. The final effect is as follows:

    What are the basic operations and concepts of getting started with SpringBoot?

    5. Note - Package path error

    We try to move HelloController to other packages, such as the following methods:

    What are the basic operations and concepts of getting started with SpringBoot?

    Run our project and found that the program reported an error, as shown in the following figure:

    What are the basic operations and concepts of getting started with SpringBoot?

    This means that the Spring Boot project did not inject objects into the container middle.

    5.1 Correct path

    When we put the container class and startup class to be injected into the same directory, as shown in the following figure:

    What are the basic operations and concepts of getting started with SpringBoot?

    At this time, the Spring Boot project can normally inject beans into the container.

    5.2 Summary

    Convention is greater than configuration

    The above situation reflects another feature of the Spring Boot project: convention is greater than configuration.

    We can also see this feature in Spring projects. For example, in Spring, the scanning path of beans must be configured, but in Spring Boot, this is not required. The Spring configuration is as follows:

    What are the basic operations and concepts of getting started with SpringBoot?

    Note:

    The classes annotated in the 5 major categories must be placed in the same directory as the startup class or in a subdirectory of the startup class, otherwise they will not be recognized

    The above is the detailed content of What are the basic operations and concepts of getting started with SpringBoot?. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
    How to properly configure apple-app-site-association file in pagoda nginx to avoid 404 errors?How to properly configure apple-app-site-association file in pagoda nginx to avoid 404 errors?Apr 19, 2025 pm 07:03 PM

    How to correctly configure apple-app-site-association file in Baota nginx? Recently, the company's iOS department sent an apple-app-site-association file and...

    What are the differences in the classification and implementation methods of the two consistency consensus algorithms?What are the differences in the classification and implementation methods of the two consistency consensus algorithms?Apr 19, 2025 pm 07:00 PM

    How to understand the classification and implementation methods of two consistency consensus algorithms? At the protocol level, there has been no new members in the selection of consistency algorithms for many years. ...

    What is the difference between IS TRUE and =True query conditions in MySQL?What is the difference between IS TRUE and =True query conditions in MySQL?Apr 19, 2025 pm 06:54 PM

    The difference between ISTRUE and =True query conditions in MySQL In MySQL database, when processing Boolean values ​​(Booleans), ISTRUE and =TRUE...

    How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling?How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling?Apr 19, 2025 pm 06:51 PM

    How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling? Using EasyExcel for Excel...

    As a Java programmer, how do you turn to audio and video development? What basic knowledge and resources do you need to learn?As a Java programmer, how do you turn to audio and video development? What basic knowledge and resources do you need to learn?Apr 19, 2025 pm 06:48 PM

    How to switch from Java programmers to audio and video development? Learning Paths and Resources Recommendations If you are a Java programmer and are participating in a video project, �...

    How to efficiently count the number of node services in MYSQL tree structure and ensure data consistency in Java?How to efficiently count the number of node services in MYSQL tree structure and ensure data consistency in Java?Apr 19, 2025 pm 06:45 PM

    How to efficiently count the number of node services in MYSQL tree structure in Java? When using MYSQL database, how to count the number of nodes in the tree structure...

    How do newcomers choose Java project management tools for backends: Maven or IntelliJ? Use the Maven that comes with IDEA or an additional download?How do newcomers choose Java project management tools for backends: Maven or IntelliJ? Use the Maven that comes with IDEA or an additional download?Apr 19, 2025 pm 06:42 PM

    How do newcomers choose Java project management tools for backends? Newbie who are just starting to learn back-end development often feel confused about choosing project management tools. Special...

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment