Detailed explanation of Maven configuration dependency of spring boot
This paper introduces the Maven configuration dependency of spring boot and shares it with you as follows:
We add spring boot starter web by referencing spring boot starter parent
It can realize the functions of web projects. Of course, it does not use spring boot start web. It can also be realized through the dependency packages added by itself, but it needs to be added one by one, which is time-consuming and laborious, and version dependency conflicts may occur. Let's look at the dependency configuration of springboot:
Using the inheritance of POM, one declaration can be used everywhere. In the top-level spring boot dependencies, use dependency management to make all sub projects reference a dependency instead of explicitly listing the version number, and place the structure information, deployment information and common dependency information in a unified location. Dependency management only declares dependencies and does not really introduce them. Therefore, sub projects need to introduce related dependencies through dependencies.
1) Spring boot dependencies consists of:
The version number that the third party depends on
Version number of the plug-in
The dependency package of springboot and the fixed version parent depend on the fixed version package. If you upgrade, you can change the dependency uniformly by modifying the version number of the parent.
Third party dependency solves the conflict of incompatible versions of third-party dependency, and it is more convenient to use third-party dependency
plug-in unit
2) Spring boot parent composition:
Add additional dependencies. Users will use third-party dependencies, but there are no dependencies in spring boot dependencies
Test related dependencies
And other plug-ins and profile configurations
3) Spring boot starter parent composition:
The parent spring boot dependencies doesn't need to be said
Rely on spring core
In the Src / main / resources directory, only application YML and application Properties is a resource file and needs to be filtered; Divide application. Under Src / main / resources YML and application Properties is also a resource file, but it does not need to be filtered. Filtering will remove ${...} from the file Replace with system attribute or project attribute value.
4)sprint-boot-starter-*
It can be managed uniformly through the parent, which is the convenience brought by the starter, one of the four artifacts of springboot. According to different functions, you can add different starters. In the spring boot source package, we can see that there are more than 50 starters in spring boot starters
The root directory in the figure is POM XML is spring boot starters. Maven's aggregation module is used. Other starters exist as subdirectories of aggregation modules. The purpose is to build multiple project modules at one time. As shown in the figure below: all starters can be built at one time by managing all starters through models:
Use the assembly plug-in to assemble a group of files, directories and dependent elements into an archive file, as shown in the following figure:
Using this plug-in, the executions executor will execute MVN assembly: assembly only once, and the path of the description file is Src / main / assembly / starter POMS assembly XML, let's look at the following description file:
The packaged file format is zip, and the module file is * * / POM XML. After the plug-in is executed, the effect is as follows:
The target folder will be generated under the SRC sibling directory and generated under it:
Dependency of all child starter files in zip file
Spring boot deployment tests, spring boot integration tests and spring boot samples all use the aggregation module function of POM in the source root directory and the directory at the same level as spring boot starters. Including spring-boot-1.5 1. Release the whole project also uses the aggregation module function. You can use mvnw to build a unified project.
Conclusion:
The Maven configuration of spring boot is roughly as described above and has been used
a. POM inheritance: one declaration, use B. POM aggregation everywhere: build multiple project modules at one time, C. other plug-ins, various configurations
It enables us to understand the spring boot implementation and deepen our understanding of Maven configuration.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.