Preface
In the process of web application development, the implementation of some common functions is generally covered, such as database access, exception handling, message queueing, cache services, OSS services, as well as interface log configuration, interface document generation, etc. If you come up with one set for each project, it will be laborious and difficult to maintain. These common functions can be integrated and centrally maintained through Spring Boot's Starter to achieve the purpose of using out-of-the-box.
The project is based on Spring Boot version 2.1.
projectaddress
The entire project is divided into the following parts:
- spring-boot-autoconfigure: The specific implementation of each function, each function is organized through the form of a package.
- spring-boot-commons: some public tool classes or shared classes
- spring-boot-dependencies: centralized maintenance and management of dependencies, centralized management of version numbers of each dependency
- spring-boot-parent: Provides a basic parent project, and the web service project can be created by inheriting the project.
- spring-boot-starters: The starter project for each function, introducing the corresponding starter means introducing the corresponding functions
spring-boot-dependencies project
This project mainly defines all dependencies in a centralized manner. DependencyManagement is declared.
<dependencyManagement> <dependencies> <dependency> <groupId></groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${}</version> <scope>import</scope> <type>pom</type> </dependency> <dependency> <groupId></groupId> <artifactId>spring-boot-commons</artifactId> <version>${}</version> </dependency> ... </dependencies> </dependencyManagement>
In this way, all dependent versions can be managed in a centralized and unified manner, and the declaration of versions can be omitted when citing in other places, such as
<dependency> <groupId></groupId> <artifactId>spring-webmvc</artifactId> <optional>true</optional> </dependency>
spring-boot-autoconfigure project
This project is a specific implementation of automatic configuration of each function and is organized in the form of a package. For example, the automatic configuration of general mapper is implemented under the tkmapper package, the automatic configuration of error processing is implemented under the error package, and so on.
The project inherits spring-boot-dependencies, and in the project, the dependency part declaration is similar to
<dependencies> <!-- spring denpendencies --> <dependency> <groupId></groupId> <artifactId>spring-webmvc</artifactId> <optional>true</optional> </dependency> <dependency> <groupId></groupId> <artifactId>spring-jdbc</artifactId> <optional>true</optional> </dependency> ... </dependencies>
No need to specify the version number. By setting optional to true, it means that the dependency will not be passed, that is, when another project refers to the project, the optional dependency will not be passed on.
In the resources/META-INF/ file, all automatic configuration classes are declared, as follows
=\ ,\ ,\ ,\ ,\ .Swagger2AutoConfiguration,\ ,\ ,\ ,\ ,\
spring-boot-starters project
This project contains multiple sub-projects divided by function, which are mainly used to introduce dependencies to meet the dependency conditions of automatic configuration, so that the automatic configuration can take effect when introducing the corresponding starter. For example, the tkmapper-spring-boot-starter integrated with general mapper depends on the following
<dependencies> <dependency> <groupId></groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId></groupId> <artifactId>mapper</artifactId> </dependency> <dependency> <groupId></groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId></groupId> <artifactId>mybatis-spring</artifactId> </dependency> </dependencies>
At the same time, the purpose of this starter is declared in resources/META-INF/, and can be written here as you like.
spring-boot-commons project
You can put some commonly used tool classes or shared classes into this project. For example, some constant definitions, encryption and decryption tools, etc.
spring-boot-parent project
This project integrates some common functions required by web applications. The application project can inherit the project and build it directly, thereby directly introducing corresponding functions.
In the following spring boot series blog posts, we will introduce the integration and application of each function in detail. At the same time, it will be constantly updated and improved to achieve the level that can be directly used in production projects.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.