xxx_core.xml:

<modules>
        <module>xxx-elasticsearch</module>
        ...
    </modules>
    <packaging>pom</packaging>
    <name>xxx-core</name>
    <description>xxx project for Spring Boot</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.16.RELEASE</version>
    </parent>

xxx_elasticsearch.xml:

<parent>
        <artifactId>xxx-core</artifactId>
        <groupId>com.xxx</groupId>
        <version>1.0.0</version>
</parent>
...
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
    ...
    </dependencies>

我们发现es的maven依赖没有加version标签,但是并没有报错且es在项目能正常使用,查看jar包es自动取了6.4.3版本:
在这里插入图片描述
怀疑是core.xml中的parent的原因。
网上查阅一番资料,猜想并没有错,添加“parent”标签里的内容后,“spring-boot-starter-parent”会为开发者提供常用jar的版本管理,所以我们不需要指定版本,使用人家提供好的就可以了。当然,指定也是可以的,这会覆盖官方默认的版本,不推荐。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐