Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify the spring-data-mongodb version using spring-boot?

I want to use the latest version of spring-data-mongodb, in order to use the full text search feature, but I don't know how I can specify this using the spring-boot-starter-data-mongodb dependence.

You can read here: maven repository that the spring-data-mongodb version is not specify.

This is my pom file:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.6.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencies>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- Spring Boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- Spring Boot Rest -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <!-- Spring Boot Test -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- Spring MongoDB integration -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>
like image 668
fontanellif Avatar asked Oct 01 '14 12:10

fontanellif


3 Answers

Spring Boot defines all its dependencies and dependency versions in the spring-boot-dependencies project. This project only contains a pom with only dependencies and versions as properties.

Spring Data releases all of its compatible releases in a so called release train and this makes sure that all dependencies of that version will work together.

When you take a closer look a the pom you will see a maven property named spring-data-releasetrain.version and for the upcoming Spring Boot 1.2 it points to the latest release train version Evans-RELEASE. The 1.1.7 version points to the previous version Dijkstra-SR4. I would suggest an upgrade from 1.1.6 to 1.1.7 just in case.

You're project already has the spring-boot-starter-parent project as its parent so in theory upgrading the Spring Data versions should be as easy as overriding the specified property.

<properties>
    <spring-data-releasetrain.version>Evans-RELEASE</spring-data-releasetrain.version>
</properties>

As mentioned earlier the use of the release train is preferred as this will make sure you get all the compatible versions.

like image 128
M. Deinum Avatar answered Oct 17 '22 09:10

M. Deinum


You can find that mongodb dependency in the parent project pom file

/../.m2/repository/org/springframework/boot/spring-boot-dependencies/2.3.0.RELEASE/spring-boot-dependencies-2.3.0.RELEASE.pom

That file defines all the dependency version for other libs SpringBoot use

<properties>
    <activemq.version>5.15.12</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    ...
    <mongodb.version>4.0.3</mongodb.version>
    ...
</properties>

So if you want to use different version for mongodb, define a properties in your pom file to override the default one like (I think this will only work if you use spring-boot-starter-parent as parent )

<properties>
    <mongodb.version>3.11.2</mongodb.version>
</properties>
like image 39
sendon1982 Avatar answered Oct 17 '22 07:10

sendon1982


Answer by @sendon1982 worked for me. Here is an example of my POM.XML. I am adding it as an answer here because I could not paste in my pom file as a comment to sendon1982 answer...

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>test.barry</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>test</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <start-class>test.barry.Main</start-class>
        <mongodb.version>4.1.0</mongodb.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
            <version>2.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-sync</artifactId>
            <version>4.1.0</version>
        </dependency>
    </dependencies>
</project>
like image 21
barrypicker Avatar answered Oct 17 '22 07:10

barrypicker