【业务功能篇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>
相关推荐
砚底藏山河3 分钟前
沪深A股:如何获取基金持股数据
java·python·数据分析·maven
一勺菠萝丶29 分钟前
Maven SNAPSHOT 父 POM 无法解析问题排查
java·maven
范什么特西1 小时前
Spring boot细节
java·spring boot·后端
java1234_小锋2 小时前
请描述 Spring Boot 的启动流程,包括 SpringApplication 的初始化和 run 方法的核心步骤。
java·数据库·spring boot
南部余额3 小时前
Maven Archetype 项目模板
java·maven·项目·archetype
Flittly3 小时前
【AgentScope Java新手村系列】(9)SpringBoot集成
java·spring boot·spring
杨运交3 小时前
[033][缓存模块]基于 Redisson 的租户隔离 Redis Key 前缀设计
spring boot
星月IWJ4 小时前
idea 工具整理
java·spring boot·intellij-idea
vx-Biye_Design4 小时前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis