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

项目中有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吗?

阅读 8k
2 个回答

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

<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的版本的。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题