
# 使用spring-boot-starter-huawei组件
spring-boot-starter-huawei组件具备开发一个基本的基于spring-boot的web项目的基本依赖，使用时只需将该组件的坐标添加到工程的pom文件中即可。
#### 使用方式
直接作为dependency依赖引入（此步骤必须）。
```
<properties>
    ...
    <com.huawei.version>2.1.9-RELEASE</com.huawei.version>
    ...
<properties>
<dependencies>
    <dependency>
        <groupId>com.huawei.devspore</groupId>
        <artifactId>spring-boot-starter-huawei</artifactId>
        <version>${com.huaweicloud.version}</version>
    </dependency>
</dependencies>
```
#### 版本管理
1. 将spring-boot-huawei-parent设置为项目的parent。 
   ```
   <parent>
       <groupId>com.huawei.devspore</groupId>
       <artifactId>spring-boot-huawei-parent</artifactId>
       <version>2.1.9-RELEASE</version>
   </parent>
   ```
   - spring-boot-huawei本身带有一个模块spring-boot-huawei-dependencies用来管理整个项目的依赖管理。
   
   - spring-boot-huawei项目下其他模块均通过spring-boot-huawei-parent作为父模块间接使用其版本管理功能。
   
   - spring-boot-starter-huawei依赖各个包的版本都受dependencies模块管理，其本身并未对依赖的包的版本显式声明。
   
   - 当spring-boot-starter-huawei作为一个jar包依赖到所需工程时，若该工程中的父模块或当前模块也声明了对相同包的依赖版本，则spring-boot-starter-huawei中声明的版本可能会被覆盖而失效。此时，若需要使用spring-boot-starter-huawei中的版本声明，建议将spring-boot-huawei-dependencies模块作为依赖管理添加至当前pom（单模块工程）或根项目模块（多模块工程）的dependencyManagement中；或者将spring-boot-huawei-parent设置为当前项目的parent（单模块工程）或根项目模块的parent（多模块工程）。
   
   
   
   
2. 将spring-boot-huawei-dependencies加入dependencyManagement。 
   ```
   <dependencyManagement>
       <dependencies>
           <dependency>
               <groupId>com.huawei.devspore</groupId>
               <artifactId>spring-boot-huawei-dependencies</artifactId>
               <version>${com.huawei.version}</version>
               <type>pom</type>
               <scope>import</scope>
           </dependency>
       </dependencies>
       ...
   </dependencyManagement>
   ```
   
   同时将父模块或本模块的其他依赖声明删除。
   spring-boot-huawei-dependencies中已经声明了对spring-boot-dependencies的依赖管理，故受该依赖管理的包版本也受spring-boot-huawei-dependencies管理。若服务为已有服务，已经声明了spring-boot-dependencies的依赖，则spring-boot-starter-huawei中使用的依赖版本可能会是spring-boot-dependencies中传递的版本。
   建议将本项目的spring-boot-dependencies的版本声明与spring-boot-huawei一致，以保证不受spring管理的优选或可选的其他依赖不会有版本或功能冲突。
   ![](https://support.huaweicloud.com/devg-astropro/public_sys-resources/notice_3.0-zh-cn.png)
   设置项目中pom的parent为spring-boot-huawei-parent和在项目pom中的dependencyManagement中添加spring-boot-huawei-dependencies这两种方式根据项目实际情况选择一种方式即可，无需同时使用，推荐使用b方式。
   
   
 
#### 组件说明
为支持及简化项目依赖，spring-boot-starter-huawei中配置了基于springboot的web项目常用的基本功能的依赖支持，目前包含以下常用依赖：
- 基本的spring环境依赖：使用spring-boot-starter完成对基本的spring环境集成，主要包含spring-core，spring-beans，spring-expression，spring-aop，spring-context，spring-aspects，spring-boot，spring-boot-autoconfigure等。
- web项目的依赖：包含web开发所需的spring-web，spring-webmvc模块，处理常用格式json数据所需的jackson-databind等。
- 服务在线文档生成工具：swagger(v2,v3)，springdoc-openapi-ui(jdk8)，springdoc-openapi-starter-webmvc-ui(jdk17)，有了这些工具后可以为服务接口字段生成openapi在线文档。
- yaml文件解析用到的snakeyaml，注解：jakarta.annotation-api。
- 常用工具类的依赖：lombok，commons-lang，guava。
spring-boot-starter-huawei中默认使用log4j2日志框架，需要根据实际情况确定是否使用该日志框架。
