Person: |
Brother Lulu. |
Qq: |
408365330 |
N01. Programming is the best way to verify learning |
N02. In order to earn money so programming, in order to make money so write good code, in order to write good code so learn |
N03. Learn to program every day |
Springboot Source Learning notes before the entry of what happened
Although there is a period of time with Springboot, but also did not pay much attention to the Springboot project packaging process What happened, the boot process details are what!
Until recently in the company's privatization of the big platform need to know more about the nature of the springboot to savor the source, starting from the origin ...
What does the Springboot program look like (figure and face)?
@SpringBootApplication@EnableAutoConfigurationpublic class EgojitApplication { public static void main(String[] args) { SpringApplication.run(EgojitApplication.class, args); }}
I first saw the special kind, this is a main program ah, and then look at, as if more than ordinary main above two annotations, always think that two eyes to understand her, and ordinary main also no difference ah, actually just understand the figure and face; ; and then I use spring-boot-maven-plugin to package; to build a jar package; If you want to know more about her "quality", then it must be from the inside out; unzip this beautiful jar;
Springboot inside the jar package (quality) noun description
The jar packages packaged by the spring-boot-maven-plugin maven plugin are referred to here as "fat jars" or "aggregate jars" (not just the way to pack fat jars, We agreed that the fat jar is the Spring-boot-maven-plugin plugin packaged jar package, I like the Convention), the Maven-jar-plugin default packaging of the jar package is called "Thin jar" or "loose jar"
Fat jar/aggregation jar
The entire project is packaged into a jar package, and all dependent jar packages are punched into a jar package
Thin jar/Loose jar
The entire project jar package is scattered, depending on the package and the project Master class or jar is parallel
N01 has connotation
Unzip found this and ordinary main program jar package is completely different Ah, contains boot-inf,meta-inf,org three directories, and then can see Boot-inf/classes is the real classpath, And the traditional jar package is extracted directly after the Classpath
N02 is featured
Meta-inf Directory I focus on the Manifest.inf file, I see I can't believe the scene, she and ordinary main difference greatly, she is not on the surface to see, the entrance main in Jarlauncher (remember it back we analyze Spring-boot-loader source from It begins); So I overturned my previous cognitive springboot of the xxxapplicaion in the main is not the normal main. It is just a normal method that is called by xxxapplicion; unlike ordinary manifest.inf it has a start-class, do not doubt that this is the xxxapplicaion we write; Spring-boot-classes points out the special class directory of Springboot; Spring-boot-lib Configure third-party dependency package directories
N03 Super Fairy
Org directory is a bit magical, there is a supernatural phenomenon Ah, my project absolutely no org.springframework.boot package AH. Where did it come from? I suspect that the life of the open project depends on the search, I am sure it is supernatural phenomenon, good fairy, not me and other people easy to understand; I think since I do not do, it is definitely a lump sum, who packed?????????????????????
Spring-boot-maven-plugin Right! That's it, I caught it; it packages the project into the directory structure we see, and copies the class from the Spring-boot-loader jar into the project;
Spring-boot-loader Analysis
The following is an analysis of the Jarlauncher execution process
Through the source code analysis process, you can know that the Spring-boot-load module gracefully implements the loading of nested jar resources through a custom jar-package structure custom ClassLoader, and then, by packaging, re-setting the startup class and organizing the jar structure. A nested jar resource load is implemented by setting a custom loader at run time;
know that we can implement our own Jarlauncher implementation archive dynamically specify the implementation of the plug-in; Since Spring-boot-loader can specify LIB and the class directory, Then we can also implement our own Jarlauncher merge more lib directories, implement external expansion lib, and then combine spring The principle of spring.factries in boot scan injected code; application hosting in the company's privatization platform I'm studying spring-boot-loader. This principle combines spring Boot in the spring.factries mechanism based on the implementation of the original Java-based Jagent method. This solution solves a lot of problems, of which the third party springboot Application log collection, performance monitoring, health check and so on can be based on this mechanism to achieve (understand how important this principle), more involved in the secret .... Haha ...