【业务功能篇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>
相关推荐
小毛驴85011 小时前
spring-boot-maven-plugin,maven-compiler-plugin 功能对比
java·python·maven
砍材农夫12 小时前
物联网实战:Spring Boot MQTT | MQTT 设备模拟器演示(附源码)
java·spring boot·后端·物联网·spring·netty
YDS82912 小时前
DeepSeek RAG&MCP + Agent智能体项目 —— Agent执行链路设计之ReAct Loop
java·spring boot·ai·agent·deepseek
摇滚侠14 小时前
Maven 入门+高深 体系外 jar 包导入 172
java·maven·jar
一 乐14 小时前
人口老龄化社区服务与管理平台|基于springboot+vue的人口老龄化社区服务与管理平台(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·人口老龄化社区服务与管理平台
ss27316 小时前
ai编程Trae cn生成图书管理系统(1)
java·数据库·spring boot·python·flask·fastapi
超梦dasgg16 小时前
Java 生产环境 Maven 实战指南
java·开发语言·maven
小马爱打代码17 小时前
SpringBoot + 延迟消息 + 时间轮:订单超时、优惠券过期等场景的高效实现方案
java·spring boot·后端
Bat U18 小时前
JavaEE|SpringBoot快速入门
spring boot·java-ee·mybatis
张小凡vip20 小时前
Spring Boot集成Kafka完整版
spring boot·kafka·linq