[Spring Boot] Quick Start Checklist

About the Author

Preface

The author has previously written a Spring Boot series, including automatic assembly principles, MVC, security, monitoring, integrated databases, integrated Redis, logs, scheduled tasks, asynchronous tasks, etc. This article will summarize all this content in one article. Liar, a quick introduction to Spring Boot in one article.

Column address:

https://blog.csdn.net/joker_zjn/category_12439661.html?spm=1001.2014.3001.5482

Table of contents

1.Principle of automatic assembly

2.MVC

3.Safety

4.Monitoring

5.Integrate database

6.Integrate Redis

7.Log

8. Scheduled tasks, asynchronous messages, asynchronous tasks

9. How to check the changes in each version of Spring Boot


1.Principle of automatic assembly

Article link:

Detailed explanation of Spring Boot automatic assembly principle_springboot automatic assembly principle__BugMan's blog-CSDN blog

As we know Spring Boot is an "out of the box" framework that encapsulates the Spring framework and simplifies the development and deployment process of Spring applications. Spring Boot works out of the box because its underlying "autowiring" mechanism automatically configures the various components of a Spring application based on the application's dependencies and needs, without having to manually write a lot of configuration code.

Regarding the automatic assembly of Spring Boot, there are tons of articles on the Internet, but most of the ideas are not very clear. They just start adjusting this method first and then that method. In fact, the entire automatic assembly of Spring Boot is divided into two major steps. :

  1. autoload
  2. automatic configuration

1.Automatic loading

Automatically load all required resources (classes, configuration files, etc.). Since some things need to be automatically loaded into the IOC, it is natural to have a list to record them, so that the medicine can be taken according to the prescription. There will be such a list of classes that need to be loaded in Spring Boot. Of course, just loading according to this list is definitely not enough, because Spring Boot also allows us to specify to exclude some classes, so Spring Boot will eventually combine the dependency list and the list that needs to be discharged to finally get all the dependencies that need to be loaded. list.

2. Automatic configuration

The automatic loading process has obtained the list of dependencies that need to be loaded. The next step is to load these dependencies into the IOC. However, just loading into the IOC is definitely not enough. The attributes in some classes also need to be initialized and assigned. Spring Boot will do this in this step. Initialize the loaded entity class according to the configuration (assign the value to the variable).

OK, the entire Spring Boot automatic assembly process is like this. Next, you can study the deeper source code process:

Detailed explanation of Spring Boot automatic assembly principle_springboot automatic assembly principle__BugMan's blog-CSDN blog

This article will give an outline and then talk about the principles and processes of automatic assembly in simple terms, so that the ideas will be very clear.

2.MVC

Article link:

How to use Spring MVC in Spring Boot_springboot uses springmvc__BugMan's blog-CSDN blog

Spring Boot integrates Spring+Spring MVC, and the essence of Spring MVC is to provide a complete set of request control components around a core Servlet (DispatcherServlet):

Therefore, to process the request in Spring Boot, you can directly configure the Spring MVC components.

3.Safety

Article link:
Spring Boot Security_springboot Security Framework__BugMan’s Blog-CSDN Blog

On the back end, security is mainly about controlling user access so that users with corresponding permissions can access corresponding resources. There are two main points:

  • Certification
  • Authorize

Authentication, identifying who it is. Authorize and verify permissions.

Spring Security was launched in Spring as a security component in the Spring ecosystem. It provides a series of security services and the ability to manage application security. The main goal of Spring Security is to protect applications from unauthorized access while supporting common authentication and authorization schemes. In Spring Boot, you can configure the application's authentication and authorization policy by introducing Spring Security. This article will introduce in detail the integrated use of Spring Security in Spring Boot.

4.Monitoring

Article link:

Spring Boot Monitoring_springboot Monitoring__BugMan's Blog-CSDN Blog

As a vital part of the operation and maintenance process, monitoring can help identify problems and failures in applications. By monitoring key performance indicators, abnormal behavior can be quickly detected, helping to troubleshoot the root cause of the problem, thereby reducing failure recovery time. Monitored data can also be used as a basis for tuning. Developers and operations teams can use this data to identify performance bottlenecks and improve code and architecture to improve application performance and response time.

Monitoring generally has two major dimensions:

  • Monitoring of servers
  • Monitoring of the application itself

Monitoring of servers:

Monitoring of servers includes real-time monitoring of current memory, disk, CPU, IO, etc.

Monitoring of the application itself:

Monitoring of the application itself includes the version information and name of the application itself, and even its dependencies, configuration, etc.

Spring Boot provides its own monitoring component - Spring Boot Actuator, which can monitor Spring Boot applications from many other dimensions in addition to the above two basic dimensions. The article will introduce the usage of this component in detail.

5.Integrate database

Article link:

Summary of common database development technologies in Spring Boot: JDBCTemplate, JPA, Mybatis_jdbctemplate and mybatis__BugMan's blog-CSDN blog

Database development has always been one of the cores of JAVA development. As the cornerstone framework of current JAVA EE, Spring Boot itself carries a JDBCTemplate framework, which basically encapsulates JDBC, making Spring Boot natively support database development. At the same time, Spring Boot does not exclude other excellent persistence layer frameworks, allowing them to smoothly access them at very low cost.

This article will introduce the three most commonly used persistence layer frameworks, JdbcTemplate, JPA, and mybatis, and how to access Spring Boot and develop on it.

6.Integrate Redis

Article link:

Using the Redis_boot project to introduce redis__BugMan's blog in Spring Boot - CSDN blog

There is no need to go into details about how commonly redis is used in current J2EE applications. Its common usage can include many key points in J2EE, including but not limited to:

  1. Cache : Redis is often used as a cache to store popular data to reduce database load. By storing frequently accessed data in Redis, the number of database queries can be significantly reduced, thereby improving application responsiveness. The Spring Cache module of the Spring framework supports integrating Redis as a cache provider.

  2. Session management : In a distributed environment, storing user session data in Redis can achieve session sharing and load balancing. This allows users to maintain the same session state across multiple application servers.

  3. Message queue : Redis's publish/subscribe mechanism makes it a powerful message queue middleware. It can be used to build event-driven applications such as notification systems, real-time chat, and task queues.

  4. Distributed locks : Redis can be used to implement distributed locks to prevent multiple clients from modifying shared resources at the same time, thereby ensuring data consistency and security.

  5. Counters and Leaderboards : Redis’ counter functionality is great for building counters and leaderboards. You can easily implement functions such as like counting, visit statistics, rankings, etc.

  6. Cache warm-up : When the application starts, Redis can be used to load the data required by the application to reduce startup time and database load.

  7. Distributed cache management : Redis supports distributed cache management, which can store cache data on multiple Redis nodes to improve availability and fault tolerance.

  8. Real-time data analysis : Redis's data structure and operation capabilities make it suitable for real-time data analysis and dashboard construction, such as real-time statistics and monitoring.

Spring Boot can easily integrate Redis, which will be explained in detail in the article.

7.Log

Article link:

Spring Boot Log__BugMan’s Blog-CSDN Blog

Due to some historical reasons, there are many logging frameworks in the JAVA field, such as Log4j, Logback, and log4j2. Because different log frameworks have different log output formats, APIs, and underlying classes, Spring Boot, as a large open source J2EE framework, needs to adapt to various logs. Spring Boot uses SLF4J as the log facade by default. LogBack is implemented as a log to record logs. Here we will not go into details about how SLF4J completes the adaptation. We only need to know that SpringBoot comes with a log facade and uses the log facade to output logs. When you want to switch log implementations, you can eliminate LogBack and introduce a new implementation. .

8. Scheduled tasks, asynchronous messages, asynchronous tasks

Scheduled task article link:

Spring Boot scheduled task_springboot scheduled task framework__BugMan's blog-CSDN blog

Asynchronous messages and asynchronous task article links:

Spring Boot asynchronous tasks, asynchronous messages_asynchronous message notification__BugMan's blog-CSDN blog

Scheduled tasks:

In J2EE applications, scheduled tasks have a wide range of uses, including but not limited to:

  1. Automation and scheduled tasks : Scheduled tasks allow developers to automate repetitive and scheduled tasks without manual intervention. This can include regular database backups, generating reports, cleaning out expired data, etc.

  2. Batch processing : Scheduled tasks are very useful in batch processing, such as processing large amounts of data at night, data import/export, etc. Scheduled tasks can trigger batch processing jobs regularly to ensure timely processing of data.

  3. Cache refresh : Scheduled tasks can be used to refresh the cache regularly to ensure that the application's cached data remains synchronized with the underlying data source. This helps provide the most up-to-date data to application users.

  4. Email notifications and reminders : Scheduled tasks can be used to send regular email notifications, reminders or alerts, such as scheduled reports, bill reminders, birthday wishes, etc.

  5. Scheduled data collection : In data warehouse and data analysis applications, scheduled tasks can be used to regularly collect data from different data sources for further analysis and reporting.

  6. Security auditing and monitoring : Scheduled tasks can be used to record and monitor application activities, such as login attempts, anomaly detection, etc. This helps provide application security and availability.

  7. Scheduled maintenance : Scheduled tasks can be used for regular maintenance of applications, including database index reconstruction, data cleaning, log cleaning and other operations.

  8. Scheduled report generation : Scheduled tasks can be used to generate and distribute periodic reports, such as sales reports, statistical data, etc.

  9. Resource management : Scheduled tasks can help manage resources, such as releasing unused resources, managing connection pools, limiting resource usage, etc.

  10. Performance monitoring and optimization : Through scheduled tasks, the performance of the application can be monitored regularly and measures can be taken to optimize the performance to ensure that the application can run efficiently.

Spring Boot provides support for scheduled tasks, which will be explained in detail in the article.

Asynchronous messages and asynchronous tasks:

First of all, we need to know that the computer's thread resources are limited, and there are only so many threads that can be opened, so threads for processing business are very precious, and these threads must be used efficiently.

In some actual business development, some operations are very time-consuming, such as executing a highly time-consuming SQL. The thread can only block in place and wait for the operation to end. This is obviously a waste of thread resources for processing business. Among these time-consuming operations, there are some operations that are not sensitive to real-time performance, such as disk IO, sending text messages and other services. You do not need to do them immediately, but just do them. Then these operations are very suitable to be done. Asynchronously, it frees up thread resources and significantly increases system throughput.

Asynchronous messages and asynchronous tasks can be directly implemented using thread pools:

You can also use MQ+ thread pool to achieve larger capacity:

Spring Boot has good support for this, which will be introduced in detail in the article.

9. How to check the changes in each version of Spring Boot

Article link:

How to check the changes in each version of Spring Boot_springboot stable version__BugMan's blog-CSDN blog

Is it enough for the content of Spring Boot to include the previous 8 points? Of course it’s not enough. When we use Spring Boot, the first thing to do is to choose which version to use. But when we open the official website, we will find something like this:

It’s a bit confusing, isn’t it? What do each version do? What are the characteristics of each? What features are there? These are what we need to know. What techniques to use to choose the Spring Boot version will be the focus of the above article.

Guess you like

Origin blog.csdn.net/Joker_ZJN/article/details/132849856