【业务功能篇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>
相关推荐
长河13 小时前
基于 Jib 实现无 Dockerfile 的 Spring Boot 应用容器化
java·spring boot·后端
Arya_aa13 小时前
一:病虫害 AI 识别系统项目初期准备与Docker初识,VM虚拟机
spring boot
敖正炀13 小时前
Spring MVC 启动全景:DispatcherServlet 与父子容器
spring boot
绿草在线15 小时前
基于SpringBoot4+Mybatis+Thymeleaf的用户管理系统开发实战
java·spring boot·thymeleaf
麦麦大数据15 小时前
基于以太坊区块链+Spring Boot+Solidity智能合约的投票系统设计与实现
spring boot·后端·区块链·智能合约·投票系统
一 乐16 小时前
茶叶商城|基于springboot + vue茶叶商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·茶叶商城系统
鱼弦16 小时前
Git 版本控制:Spring Boot 项目的分支管理与协作
spring boot
devpotato1 天前
Spring Boot mTLS 报 `keystore password was incorrect`:不一定是密码错了
spring boot·tls·pkcs12·mtls
keep one's resolveY1 天前
SpringBoot实现重试机制的四种方案
java·spring boot·后端