【业务功能篇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>
相关推荐
JavaGuru_LiuYu3 小时前
Spring Boot 整合 SSE(Server-Sent Events)
java·spring boot·后端·sse
彭于晏Yan3 小时前
Springboot实现数据脱敏
java·spring boot·后端
super_lzb3 小时前
springboot打war包时将外部配置文件打入到war包内
java·spring boot·后端·maven
钱多多_qdd4 小时前
springboot注解(二)
java·spring boot·后端
钱多多_qdd5 小时前
springboot注解(五)
java·spring boot·后端
小毛驴8506 小时前
Maven同时配置阿里云仓库和私有仓库
java·阿里云·maven
不如打代码KK6 小时前
Springboot如何解决跨域问题?
java·spring boot·后端
Java 码农6 小时前
gitlab gitrunner springboot 多环境多分支部署 (非容器方式,使用原生linux 环境)
linux·spring boot·gitlab
enjoy编程7 小时前
Spring boot 4 探究netty的关键知识点
spring boot·设计模式·reactor·netty·多线程
一 乐7 小时前
餐厅点餐|基于springboot + vue餐厅点餐系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端