Spring Boot 多模块常见错误

Spring Boot 多模块常见错误

版本锁定

1、在父项目的 POM.XML中使用 对项目依赖的版本进行管理

  • 常见 模板
<properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spotless-maven-plugin.version>2.22.1</spotless-maven-plugin.version>
        <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
        <!-- framework start -->
        <spring-boot.version>2.3.12.RELEASE</spring-boot.version>
        <spring-cloud-dependencies.version>Hoxton.SR12</spring-cloud-dependencies.version>
        <spring-cloud-alibaba-dependencies.version>2.2.9.RELEASE</spring-cloud-alibaba-dependencies.version>
        <spring-cloud-starter-openfeign.version>2.2.5.RELEASE</spring-cloud-starter-openfeign.version>
        <knife4j-spring-boot-starter.version>3.0.3</knife4j-spring-boot-starter.version>
        <redisson-spring-boot-starter.version>3.17.3</redisson-spring-boot-starter.version>
        <shardingsphere-jdbc-core-spring-boot-starter.version>5.2.0
        </shardingsphere-jdbc-core-spring-boot-starter.version>
        <spring-cloud-starter-stream-rocketmq.version>2.2.6.RELEASE</spring-cloud-starter-stream-rocketmq.version>
        <spring-cloud-starter-alibaba-sentinel.version>2.2.7.RELEASE</spring-cloud-starter-alibaba-sentinel.version>
        <minio.verion>8.4.2</minio.verion>
        <hippo4j-config.version>1.4.3</hippo4j-config.version>
        <seata.version>1.5.2</seata.version>
        <xxl-job.version>2.3.1</xxl-job.version>
        <canal-client.version>1.1.6</canal-client.version>
        <apm-toolkit-trace.version>8.14.0</apm-toolkit-trace.version>
        <!-- framework end -->
        <!-- tool start -->
        <lombok.version>1.18.24</lombok.version>
        <mapstruct.version>1.4.2.Final</mapstruct.version>
        <dozer.version>6.5.2</dozer.version>
        <fastjson2.version>2.0.7</fastjson2.version>
        <hutool-all.version>5.8.2</hutool-all.version>
        <guava.version>31.1-jre</guava.version>
        <hibernate-validator.version>5.4.2.Final</hibernate-validator.version>
        <validation-api.version>2.0.1.Final</validation-api.version>
        <jjwt.version>0.9.1</jjwt.version>
        <okhttp3.version>4.9.3</okhttp3.version>
        <javafaker.version>1.0.2</javafaker.version>
        <jetcache.version>2.7.3</jetcache.version>
        <faker.version>1.0.2</faker.version>
        <!-- tool end -->
    </properties>

2、使用 标签对子项目的依赖版本进行锁定

  • 常见模板
 <dependencyManagement>

        <dependencies>
            
          <!-- 主要是对 spring-boot 所引用的核心版本进行管理 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- 主要是对 spring-cloud 所引用的核心版本进行管理 -->
             <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud-dependencies.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            
           <!-- 主要是对 spring-cloud-alibaba 所引用的核心版本进行管理 -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba-dependencies.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>

    </dependencyManagement>
  • 注意事项 : spring-boot 多模块项目在进行版本管理时,需要在父项目的 中进行引入,不然可能会导致子项目中的依赖引入失败
posted @ 2023-05-18 14:52  ayiZzzz  阅读(89)  评论(0)    收藏  举报