简体   繁体   中英

How can i use spring data mongodb 2.1.0.RELEASE with spring boot 2.0.5 and Jhipster 5.3.3?

I am using spring-boot 2.0.5.RELEASE with Jhipster 5.3.3, my pom is as follow :

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.github.jhipster</groupId>
            <artifactId>jhipster-dependencies</artifactId>
            <version>${jhipster-dependencies.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- jhipster-needle-maven-add-dependency-management -->
    </dependencies>
</dependencyManagement>
...
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
...

Now as i learned that spring data has support released for MongoDB4 transaction management, i wanna give it a try, cause it sounds very cool !

Based on spring reference documentation : https://docs.spring.io/spring-data/mongodb/docs/2.1.0.RELEASE/reference/html/#dependencies

using spring data mongodb 2.1.0.RELEASE with spring boot is as easy as adding the BOM of releasetrain. Which i did, and my pom become :

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.github.jhipster</groupId>
            <artifactId>jhipster-dependencies</artifactId>
            <version>${jhipster-dependencies.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- jhipster-needle-maven-add-dependency-management -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-releasetrain</artifactId>
            <version>Lovelace-RELEASE</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>

</dependencyManagement> 

But this didn't bring any of spring data mongodb 2.1.0 jars, only the pom of the releasetrain lovelace. Maven only download the pom of the releasetrain and keep downloading the spring data mongodb 2.0.10 that is shipped with spring boot 2.0.5.

add spring-data-mongodb in your pom.xml too

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
    </dependency>

I find the way to do it, since i am using Jhipster as a parent to my project pom, i hade to declare the lovelace dependency management before the Jhipster one, so my pom become :

<dependencyManagement>
  <dependencies>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-releasetrain</artifactId>
        <version>Lovelace-RELEASE</version>
        <scope>import</scope>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>io.github.jhipster</groupId>
        <artifactId>jhipster-dependencies</artifactId>
        <version>${jhipster-dependencies.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
</dependencies>

</dependencyManagement> 
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

Maven then will download the version of spring data mongodb specified in depenedncy management of lovelace.

I had to read the spring boot reference guide to understand that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM