【业务功能篇62】Spring boot maven多模块打包时子模块报错问题

程序包 com.xxx.common.utils不存在或者xxx找不到符号

  • 我们项目中一般都是会分成多个module模块,做到解耦,方便后续做微服务拆分模块,可以直接就每个模块进行打包拎出来执行部署
  • 这样就会有模块之间的调用,比如API模块会被Service模块调用,被调用的模块,我们都是用maven将要用到的模块打成jar包,需要调用的模块,在pom.xml文件中引入其模块坐标即可
  • service启动编译时报错:程序包com.xxx.xxx.不存在和找不到符号加粗样式。
  • 原因:SpringBoot工程打包编译时,会生成两种jar包,一种是普通的jar,另一种是可执行jar。默认情况下,这两种jar的名称相同,在不做配置的情况下,普通的jar先生成,可执行jar后生成,造成可执行jar会覆盖普通的jar。而Service模块无法依赖API模块的可执行jar,所以编译失败:程序包不存在。
  • 解决:在所有需要被依赖的module工程中,pom.xml文件中加入配置<configuration>即可:
  • 添加后,再install就成功了
XML 复制代码
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>

    </build>
相关推荐
布朗克1687 分钟前
38 Spring Boot入门——自动配置、核心注解与Starter机制
java·spring boot·后端
半夜燃烧的香烟19 分钟前
springboot3.0 集成minio上传文件,支持多个桶名
java·开发语言·spring boot
m0_5477229229 分钟前
从零搭建乒乓球比赛管理系统——Spring Boot + 原生 HTML 实战
spring boot·后端·html
小马爱打代码1 小时前
Spring Boot 自动装配流程
java·spring boot·后端
我登哥MVP1 小时前
SpringCloud 核心组件解析:分布式配置管理
java·spring boot·分布式·spring·spring cloud·java-ee·maven
Flittly1 小时前
【AgentScope Java新手村系列】(6)Hook与Middleware
java·spring boot·笔记·spring·ai
何中应1 小时前
Nexus如何配置阿里云镜像源(Maven)
阿里云·maven·nexus
技术小结-李爽1 小时前
【工具】Maven二进制包目录结构说明
java·maven
i220818 Faiz Ul1 小时前
药店管理|基于springboot + vue药店管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·美食分享系统