SpringBoot3 Getting Started Chapter 1

status quo

As the saying goes, buy new instead of old, and the same is true for learning technology, learning the latest technology, because the times will give the most generous returns to the pioneers

The first chapter builds the SpringBoot project

This is because I haven’t used SpringBoot for a long time, so I have forgotten a lot of things, which is very annoying. Fortunately,
insert image description here
there are not many things in it. It is very simple to start this thing. The
default access port, you have to recite it

http://localhost:8080/

测试返回hello请求成功,在经过下文的代码修改后

http://localhost:8080/hello


insert image description here

Chapter 2 Code Structure

insert image description here
insert image description here

package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@Controller
public class HelloController {
    
    
    @GetMapping("/hello")
    public String hello(){
    
    


        return "Hello,Spring Boot 3";
    }
}
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MainApplication {
    
    

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

}

Packaging test: fat-jar large-volume jar package

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

First click clean, then click package to generate a jar package
insert image description here

Three characteristics of the SpringBoot framework

1. Simplify integration

Import related scenes and have related functions. Scenario starter
All scenarios supported by default: https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems.starters
● Official scenarios: named as : spring-boot-starter-*
● Third-party provided scenarios: named: *-spring-boot-starter

Once the scene is imported, everything is ready

2. Simplify development

Direct business development without writing any configuration

3. Simplified configuration

application.properties:
● Centralized management configuration. Just modify this file.
● Configurations basically have default values
​​● All configurations that can be written are in: https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties

4. Simplify deployment

Packaged as an executable jar package.
There is a java environment on the linux server.

5. Simplify operation and maintenance

Modify configuration (put an application.properties file externally), monitor, and health check.

Guess you like

Origin blog.csdn.net/CNMBZY/article/details/132288441