spring-boot多个模块如何管理多重继承关系

发布于 2022-09-05 23:39:33 字数 1852 浏览 16 评论 0

项目中有ABCDE这五个项目,
其中A打算作为其余四个项目的父模块,用来管理依赖,其余的四个项目打算都是用spring-boot来开发,请问这个依赖关系我如何在pom.xml中去定义?
我说一下我目前的方案
A:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
</parent>
<modules>
    <module>../B</module>
    <module>../C</module>
    <module>../D</module>
    <module>../E</module>
</modules>
<packing>pom</packing>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</dependencyManagement>

B:

<parent>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    <relativePath>../A/pom.xml</relativePath>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

其余的C、D、E的pom.xml与B类似,我这样配置后,B提示我spring-boot-starter-web要指定版本号,B的父级模块已经有了spring-boot-starter-web这个依赖,并且版本号也已经可以从spring-boot-starter-parent这个模块来获取,为什么会出现找不到版本号呢?
还有如果我不使用spring-boot-starter-parent只使用spring-boot-starter-web时项目依然可以运行这是为啥?spring-boot项目不依赖spring-boot-starter-parent吗?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还不是爱你 2022-09-12 23:39:34
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</dependencyManagement>

在A项目中的pom不需要添加这个依赖管理,你的子模块中需要spring-boot-starter-web这个依赖的话直接添加在子模块的pom上就可以了,不需要指定版本,版本是根据你A项目的spring-boot-starter-parent的版本的。

末蓝 2022-09-12 23:39:33

说明pom关系没对应上,我理解不用整什么相对路径的,直接用IDE创建多模块项目吧

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文