Contents
2024.4.17 Wednesday
1. Overview
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
Prerequisite: Using IDEA
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
- 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.
- 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.
- 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.
- Indeed, this is the process from Java enterprise applications -> J2EE -> Spring -> Spring Boot.
- 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;
- 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.
- 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.
- 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.
- 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
1.3.2.1.2. Select configuration
1.3.2.1.3. Extract to an appropriate folder and open with IDEA
1.3.2.1.4. Delete the files highlighted in blue
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/
2024.4.18 Thursday
1.3.2.2. Creating through IDEA
1.3.2.2.1. Create a new project
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
You need to add Maven support (similar to adding web support)
https://blog.csdn.net/dream_ready/article/details/133965467
1.3.3. Continue to edit helloworld1 based on the above operations being runnable
1.3.3.1. Create a new file
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
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
Find this jar file in the system folder, open by shift + right-clicking to open PowerShell window 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.
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
Interesting design website: https://www.bootschool.net/ascii-art
1.3.4.3. Customize the start-up banner
Create src/main/resources/banner.txt
▐▒▒░▄
▒▒▒▒▒▒▒▒▄
▐▒▒▒▒▒▒▒▒▒▒▒▄ ▄▄▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▄ ▄▄▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄ ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▌
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄ ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▄░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░
▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄ ▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▄▄▄▄░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▀▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▀
▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒░▄▄▄ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▄▄▄ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒ ▀█▀ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▐██▀ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒░
▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▐▒▒▒▒▒▒▒▒▒▒▒▒▒▄ ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄ ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▄ ▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒░░░░░░░░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░▒▒▒▒▒▒▒▒
▐▒░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░▐▒▒▒▒▒▒
▒▒░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀░░░░▄░░░▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░▐▒▒▒▒▒▒▒
▐▒▒░░░░░░░▄░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░▒▒▒▒▒▒▒▒▒▒▒▒
▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄░▀▒▒▒▒▀░▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒