Preview
I had a good internship this summer. Unexpectedly, the epidemic suddenly appeared in Nanjing. I further learned relevant knowledge and learned from the great God at Xiaopo station. After some twists and turns, I made a general demo. However, I was really happy to be successfully deployed to Alibaba cloud. The corners of my mouth rose wildly, and I also sent a link to my friends. It was a rare joy to share The following is a little systematic combing of these half understood knowledge, which can also be regarded as a foundation for yourself to do relevant projects in the future
Adoption of technical tools
- SpringBoot
- Thymeleaf
- JPA
- Semantic UI
- html \ css \ js
- jquery
- Third party plug-in (css effect, md editing display)
- Alibaba cloud ECS
- maven
- log4j
- final shell
- Pagoda panel
Springboot
Spring boot is the mainstream java technology framework, which has a strong ecosystem With the help of its official website
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
Indeed, to a large extent, developing a demo is not about how powerful your technology is, but on the shoulders of giants. If you let yourself compile the bytecode and put it into the corresponding files on the server in different categories, the workload is really heavy Compared with jsp, which has a higher degree of front-end and back-end coupling, the interface provides a troublesome way. It is better to use springboot, which makes it convenient for developers to make their own demo, but it also intensifies the competition in the industry and the degree of students' involution. Which day is the end
Springboot smaller
I've seen some analysis here, but I feel that there are differences, and the version is updated quickly. Many things are changing. I'm looking at 2.5 3 version, download the source code, read the author's notes, plus other relevant materials, have the following understanding There are some very important classes, which are listed below
SpringApplication class
This Class that can be used to bootstrap and launch a Spring application from a Java main method. By default class will perform the following steps to bootstrap your application
Through it, we can start a program. Calling its static run method (in fact, an internal new instance can be used again) is one way. There are other ways to make our demo run
ApplicationContextInitializer
Springboot startup process
Its startup process is very complex. It can do so many things. First, it has the annotation @ SpringApplication, and the SpringApplication class mentioned above,
1. Create an ApplicationContext instance according to the classpath. Its constructor also has a parameter of primarySources. This instance includes listener, initializer, project application type, startup class collection and class loader
Create an appropriate ApplicationContext instance (depending on your classpath)
Assert that primarySources cannot be null. If it is null, throw an exception prompt
Class of the incoming startup class
There are three types to judge the current project type: NONE, SERVLET and REACTIVE
Setting ApplicationContextInitializer
Set listener
Judge the main class and initialize the entry class
2. The instance calls the run method, which is too complex
public ConfigurableApplicationContext run(String... args) { //Create timer StopWatch stopWatch = new StopWatch(); //Timing start stopWatch.start(); //Define context object DefaultBootstrapContext bootstrapContext = createBootstrapContext(); ConfigurableApplicationContext context = null; //Headless mode setting configureHeadlessProperty(); //Load spring applicationrunlisteners listener SpringApplicationRunListeners listeners = getRunListeners(args); //Send ApplicationStartingEvent event listeners.starting(bootstrapContext, this.mainApplicationClass); try { //Encapsulates the ApplicationArguments object ApplicationArguments applicationArguments = new DefaultApplicationArguments(args); //Configure environment module ConfigurableEnvironment environment = prepareEnvironment(listeners, bootstrapContext, applicationArguments); //Configure the bean information to be ignored according to the environment information configureIgnoreBeanInfo(environment); //You can also customize the banner by printing the banner logo Banner printedBanner = printBanner(environment); //Create ApplicationContext application context context = createApplicationContext(); context.setApplicationStartup(this.applicationStartup); //ApplicationContext basic property configuration prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner); //Refresh context refreshContext(context); //The refreshed operation is extended by the subclass afterRefresh(context, applicationArguments); //Timing end stopWatch.stop(); //Print log if (this.logStartupInfo) { new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch); } //Send the ApplicationStartedEvent event to mark that the spring container has been refreshed, and all bean instances have been loaded listeners.started(context); //Find the bean with CommandLineRunner or ApplicationRunner registered in the container, traverse and execute the run method callRunners(context, applicationArguments); } catch (Throwable ex) { //Send ApplicationFailedEvent event, which indicates that SpringBoot fails to start handleRunFailure(context, ex, listeners); throw new IllegalStateException(ex); } try { //Send the ApplicationReadyEvent event, which indicates that the spring application is already running, that is, it has been successfully started and can receive service requests. listeners.running(context); } catch (Throwable ex) { //Exceptions are reported, but no events are sent handleRunFailure(context, ex, null); throw new IllegalStateException(ex); } return context; }
Spring boot processing request
This area is actually quite large. The simplified use of the bottom layer is really complex. Here, post a diagram on the official website to explain your understanding
- The dispatcher servlet receives and intercepts user requests
The url requested by the user is actually divided into three parts: server domain name, project name controller, and may also carry some parameters
- DispatcherServlet automatically calls HandlerMapping processor mapping to find the corresponding Handler and return HandlerExecution
- HandlerExecution represents a specific Handler
- DispatcherServlet calls HandlerAdapter to execute Handler
- The Handler asks the specific Controller to perform some service operations and add some data to the loading of dao's CRUD model object
- Then return the model information to the HandlerAdapter through the HandlerAdapter
- HandlerAdapter calls ViewResolver to parse views like thymeleaf
- HandlerAdapter returns the view to the browser, which parses the view and presents it to the user
Official account: British short love rice, welcome.
This article is composed of blog one article multi posting platform OpenWrite release!