In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use SpringBoot to integrate the common functions of Web projects, the article is very detailed, has a certain reference value, interested friends must read it!
Preface
In the process of Web application development, it generally covers the implementation of some common functions, such as database access, exception handling, message queue, cache service, OSS service, as well as interface log configuration, interface document generation and so on. If there is 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 out-of-the-box use.
The project is based on Spring Boot 2.1.5.RELEASE.
The whole project is divided into the following parts:
Spring-boot-autoconfigure: specific functional implementation, each function organizes spring-boot-commons in the form of package: some common tool classes or shared classes spring-boot-dependencies: centralized maintenance management of dependencies, centralized management of each dependent version number spring-boot-parent: provides a basic parent project, and web service projects can inherit this project to create spring-boot-starters: starter projects for each function. Introducing the corresponding starter means introducing the corresponding function.
Spring-boot-dependencies project
The main purpose of this project is to define all dependencies centrally. Declare dependencies through dependencyManagement
Org.springframework.bootspring-boot-dependencies$ {spring-boot.version} importpomcn.jboost.springbootspring-boot-commons$ {base-spring-boot.version}...
In this way, all dependent versions can be centrally managed, and version declarations can be omitted when referenced elsewhere, such as
Org.springframeworkspring-webmvctrue
Spring-boot-autoconfigure project
The project is the concrete realization of automatic configuration of each function, which is organized in the form of package, such as the automatic configuration of general Mapper under tkmapper package, the automatic configuration of error handling under error package, and so on.
The project inherits spring-boot-dependencies, and in the project's pom.xml, the dependency section declares something like
Org.springframeworkspring-webmvctrueorg.springframeworkspring-jdbctrue...
You no longer need to specify a version number. By setting optional to true, it means that the dependency will not be passed, that is, when another project references the project, optional's dependency will not be passed on.
In the resources/META-INF/spring.factories file, all the automatic configuration classes are declared, as follows
Org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ cn.jboost.springboot.autoconfig.tkmapper.MapperAutoConfiguration,\ cn.jboost.springboot.autoconfig.aoplog.AopLoggerAutoConfiguration,\ cn.jboost.springboot.autoconfig.alimq.config.AliMQAutoConfiguration,\ cn.jboost.springboot.autoconfig.qiniu.QiniuAutoConfiguration,\ cn.jboost.springboot.autoconfig.swagger.Swagger2AutoConfiguration,\ cn.jboost.springboot.autoconfig.druid.DruidAutoConfiguration,\ cn.jboost.springboot.autoconfig.error.exception.ExceptionHandlerAutoConfiguration,\ cn.jboost.springboot.autoconfig.alimns.MnsAutoConfiguration,\ cn.jboost.springboot.autoconfig.redis.RedisClientAutoConfiguration \ cn.jboost.springboot.autoconfig.web.CORSAutoConfiguration
Spring-boot-starters project this project contains multiple sub-projects divided by function, which is mainly used to introduce dependencies to achieve the dependency condition of automatic configuration, so that when the corresponding starter is introduced, the automatic configuration can take effect. For example, the tkmapper-spring-boot-starter dependencies of general Mapper integration are as follows
Org.springframeworkspring-jdbctk.mybatismapperorg.mybatismybatisorg.mybatismybatis-spring
At the same time, the purpose of the starter is declared in resources/META-INF/spring.provides, which can be written here at will.
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 tool classes, etc.
Spring-boot-parent project
The project integrates some common functions needed by the Web application, and the application project can inherit the project to build, thus directly introducing the corresponding functions.
In the following spring boot series of blog posts, the integration and application of each function will be introduced in detail. At the same time, it will be constantly updated and improved to reach the level that can be directly used in production projects.
The above is all the contents of the article "how to use SpringBoot to integrate the common functions of Web projects". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.