Simple combing of spring boot MVC process

When the web application receives a request, it will send the request to org.springframework.web.servlet.DispatcherServlet#doDispatch The flow of MVC, that is, the flow of the doDispatch method Find Handler mappedHandler = getHandler(processedRequest); Find HandlerAdapter HandlerAdapter ha = getHandlerAdapter(mappedHandler. getHandler()); execute handler mv = ha. handle(processedRequest, response, mappedHandler. getHandler()); result processing processDispatchResult(processedRequest, response, mappedHandler, mv, dispatchException); In […]

Spring Boot two global configurations and two annotations

1. Overview of global configuration files The global configuration file can modify some default configuration values. Spring Boot uses an or application.yaml file as a global configuration file, which is stored in the src/main/resource directory or /config in the class path, and the resource directory is generally selected. 2. configuration file (1) Create […]

Spring Boot two global configurations and two annotations

Article directory Zero. Learning Objectives 1. Overview of the global configuration file Two, configuration file 1. Create Spring Boot’s Web project PropertiesDemo (1) Create a project using Spring Initializr 2. Add relevant configuration in the application properties file 3. Configuration and use of object types (1) Create the Pet class (2) Create the Person […]

springboot integrates Redis to save commodity and commodity inventory information

1. Add dependencies and configuration <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> Add the following configuration in application.yaml: spring: redis: # address host: localhost # port, default is 6379 port: 6379 # password password: # Connection timeout timeout: 10s lettuce: pool: # The minimum idle connection in the connection pool min-idle: 0 # The maximum idle connection in […]

How to dynamically refresh the configuration of SpringBoot (scheme)

For microservices, configuration localization is a big problem. It is impossible to restart the service every time you need to change the configuration. Therefore, the final solution is to externalize the configuration and host it on a platform to achieve unnecessary Restart the service to modify multiple valid purposes at once. But for the Spring […]

SpringBoot master-slave data source switching, Mybatis Plus annotation method association query

1. Project structure 2. Main code 1 Use druid to configure the master-slave data source # data source configuration spring: datasource: type: driverClassName: com.mysql.cj.jdbc.Driver druid: # Main database data source db1: url: jdbc:mysql:// & amp;characterEncoding=utf8 & amp;zeroDateTimeBehavior=convertToNull & amp;useSSL=true & amp;serverTimezone=GMT+8 username: root password: xiaozhu123456 # From the database data source (temporarily local) db2: […]

How to dynamically refresh the configuration of SpringBoot (custom)

The custom part of this article includes 1. Custom refresh event (with RefreshScope to achieve automatic refresh) 2. Force refresh the context (restart the entire ApplicationContext) 3. Implement Http interface loading of configuration files (similar to Nacos) Custom refresh event (with RefreshScope to achieve automatic refresh) Manual refresh of configuration based on Spring uses […]

Example explanation of redis using pipeline mode to write performance tuning under Java Springboot

Instance of redis write pipeline mode performance tuning under Springboot 1. Real scene In the process of producing real projects, it is necessary to write the data of the database to redis synchronously, and encounter the bottleneck of writing to redis during this process. Every time the project is started, the database data must be […]

Realize timed task parsing headerless .csv file into pgsql library (java, SpringBoot)

1. Scheduled tasks package; import; import; import; import; import; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.stereotype.Component; import; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author stb * @date 2023-05-24 * @description Synchronize XXX data regularly */ @Slf4j @Component […]

In-depth analysis of Spring Boot, Spring MVC and Spring Cloud

Foreword Spring Boot, Spring MVC and Spring Cloud are three very important frameworks in Java enterprise development. They each have different capabilities, but can also be used together to create powerful and scalable applications. foreword Spring Boot: Simplifying Spring Application Development Spring MVC: Web Application Development Framework Spring Cloud: Microservice Architecture In conjunction with Spring […]