【WEEK8】 【DAY3】【DAY4】Overview of Spring Boot【English Version】

2024.4.17 Wednesday

1. Overview

Insert image description here

1.1. Start with a crash course to get the gist

The SSM Trio:
Spring: “Managed”
MyBatis: Object Relational Mapping (ORM)
Spring Boot: Replaces SSM
Insert image description here
Insert image description here
Prerequisite: Using IDEA
Insert image description here

1.2. Getting Started with Spring Boot

1.2.1. What is Spring

1.2.1.1. Spring is an open-source framework, a lightweight Java development framework that emerged in 2003, created by Rod Johnson.
1.2.1.2. Spring was developed to simplify enterprise application development and reduce complexity.

1.2.2. How Spring Simplifies Java Development

To reduce the complexity of Java development, Spring employs the following four key strategies:
1.2.2.1. Lightweight and minimally invasive programming based on POJOs; everything is a bean;
1.2.2.2. Achieving loose coupling through IoC, Dependency Injection (DI), and interface orientation;
1.2.2.3. Declarative programming based on aspects (AOP) and conventions;
1.2.2.4. Reducing boilerplate code through aspects and templates, such as RedisTemplate, xxxTemplate;

1.2.3. What is Spring Boot

  1. Those who have studied Java web development know that developing a web application from scratch, starting with Servlet combined with Tomcat to run a Hello World program, involves many steps. Later frameworks like Struts and then Spring MVC were used, leading up to today’s Spring Boot. In a year or two, other web frameworks may emerge. Have you experienced the continual evolution of frameworks and the constant changes and renovations in the technologies used in your own projects? It’s advisable to experience this process at least once.
  2. Back to the point, what is Spring Boot? It is a Java web development framework similar to Spring MVC. Compared to other Java web frameworks, its advantage, as stated officially, is that it simplifies development, adhering to the principle that conventions should be favored over configuration. It enables rapid development of web applications, allowing for the development of an HTTP interface with just a few lines of code.
  3. The development of all technology frameworks seems to follow a common thread: from a complex application scenario, a standard framework emerges. People only need to configure it without needing to implement it themselves, which is where powerful configuration features become advantageous. As it develops, people select the most practical features and design essence based on real-world application scenarios and re-engineer some lightweight frameworks. Later, to improve development efficiency, they begin to promote “convention over configuration,” which leads to the emergence of one-stop solutions.
  4. Indeed, this is the process from Java enterprise applications -> J2EE -> Spring -> Spring Boot.
  5. As Spring continues to develop and encompasses more areas, integrating various files in project development slowly becomes less user-friendly and simple, contrary to its original philosophy, even being dubbed a configuration hell. Spring Boot was abstracted against this background as a development framework intended to make it easier for everyone to use Spring, integrate various middleware, and open-source software more easily;
  6. Spring Boot is based on Spring development. It does not provide the core features or extensions of the Spring framework itself but is a tool closely integrated with the Spring framework to enhance the experience of Spring developers. Spring Boot adopts the core philosophy of convention over configuration, providing many default settings, meaning most Spring Boot applications require very little Spring configuration. It also integrates a lot of common third-party library configurations (such as Redis, MongoDB, Jpa, RabbitMQ, Quartz, etc.), which can be used almost out of the box with zero configuration in Spring Boot applications.
  7. Simply put, Spring Boot is not a new framework; it comes with default configurations for many frameworks, similar to how Maven integrates all jars; Spring Boot integrates all frameworks.
  8. Spring Boot, born into a distinguished family and starting from a relatively high starting point, has developed a sufficiently mature ecosystem over the years. Spring Boot has rightfully become one of the hottest technologies in the Java domain.
  9. The main advantages of Spring Boot are:
    • Faster onboarding for all Spring developers
    • Out-of-the-box, providing various default configurations to simplify project setup
    • Embedded containers simplify web projects
    • No need for redundant code generation and XML configuration

It’s really exciting, let’s quickly experience the feeling of developing an interface!

1.3. Your First Spring Boot Project

1.3.1. Preparation

We will learn how to quickly create a Spring Boot application and implement a simple HTTP request handler. Through this example, you’ll get a preliminary understanding of Spring Boot and experience its simple structure and rapid development characteristics.
1.3.1.1. JDK 1.8
1.3.1.2. Maven 3.5.4
1.3.1.3. Spring Boot
1.3.1.4. IDEA

1.3.2. Creating a Basic Project Overview

The official site provides a quick generation tool, which IDEA has integrated.

1.3.2.1. Using the Official Configurator

1.3.2.1.1. Website: Spring Boot -> Spring Initializr
Insert image description here
1.3.2.1.2. Select configuration
Insert image description here
1.3.2.1.3. Extract to an appropriate folder and open with IDEA
Insert image description here
1.3.2.1.4. Delete the files highlighted in blue
Insert image description here
1.3.2.1.5. Modify configuration to prevent error “java: invalid target release: 19”
Refer to the blog: https://blog.csdn.net/2401_83329143/article/details/137220099
Then refresh Maven (otherwise, there will still be errors)
Spring Boot start-up error - class file has wrong version 61.0, should be 52.0: https://blog.csdn.net/qq_49619863/article/details/128047256
Solution: IDEA java: Warning: source release 17 requires target release 17: https://blog.csdn.net/Jason_HD/article/details/131194074
1.3.2.1.6. Run
Enter URL: http://localhost:8080/
Insert image description here

2024.4.18 Thursday

1.3.2.2. Creating through IDEA

1.3.2.2.1. Create a new project
Insert image description here
Insert image description here
Other modifications are the same as those mentioned in section 1.3.2.1 from downloading via the official website.
1.3.2.2.2. If the run button is not active, as shown below
Insert image description here
You need to add Maven support (similar to adding web support)
https://blog.csdn.net/dream_ready/article/details/133965467
Insert image description here

1.3.3. Continue to edit helloworld1 based on the above operations being runnable

1.3.3.1. Create a new file

Insert image description here

1.3.3.2. Modify HelloController.java
package com.P3.helloworld1.controller;

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

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String hello(){
        //Call business in the interface, receive frontend parameters
        return "hello world";
    }
}
1.3.3.3. Run

http://localhost:8080/hello
Insert image description here

You may encounter a port occupancy issue; see the blog for a solution: https://blog.csdn.net/2401_83329143/article/details/137223372

1.3.3.4. Package into a jar

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Find this jar file in the system folder, open by shift + right-clicking to open PowerShell window here
Insert image description here
Enter java -jar .\helloworld1-0.0.1-SNAPSHOT.jar (jar file name can be auto-completed with tab key)
You need to stop the project in IDEA first, otherwise, it will fail to run here.
Insert image description here
Now running http://localhost:8080/hello will display the same effect as in 1.3.3.3

1.3.4. Edit springboot-01-helloworld

1.3.4.1. Change port number

Modify the application.properties file

spring.application.name=springboot-01-helloworld
server.port=8081
1.3.4.2. Run

http://localhost:8081/hello/hello
Insert image description here
Interesting design website: https://www.bootschool.net/ascii-art

1.3.4.3. Customize the start-up banner

Create src/main/resources/banner.txt

      ▐▒▒░▄                                                                                        
       ▒▒▒▒▒▒▒▒▄                                                                                   
       ▐▒▒▒▒▒▒▒▒▒▒▒▄                                                                         ▄▄▒▒  
        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▄                                                               ▄▄▒▒▒▒▒▒▒▒  
        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄                                                       ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▌  
         ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄                                               ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒   
          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒                                        ▄░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░   
           ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄                                ▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒    
             ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▄▄▄▄░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒     
              ▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀      
                ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒        
                  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒          
                    ▀▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀            
                       ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▀               
                     ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░                  
                     ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒                 
                    ▒▒▒▒▒▒▒▒▒▒░▄▄▄  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▄▄▄  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒                
                   ▒▒▒▒▒▒▒▒▒▒▒ ▀█▀   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▐██▀   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒░               
                  ▒▒▒▒▒▒▒▒▒▒▒▒       ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░       ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒               
                 ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▄   ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄   ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒              
                 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒              
                ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▄  ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒             
                ▒▒░░░░░░░░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░▒▒▒▒▒▒▒▒            
               ▐▒░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░▐▒▒▒▒▒▒            
               ▒▒░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀░░░░▄░░░▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░▐▒▒▒▒▒▒▒           
               ▐▒▒░░░░░░░▄░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░▒▒▒▒▒▒▒▒           
                ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░▒▒▒▒▒▒▒▒▒▒▒▒          
                ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒          
                 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄░▀▒▒▒▒▀░▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒         
                  ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒         

1.3.4.4. After the restart

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值