4

While trying to run Spring-boot application (v2.1.0) getting below error:

Description:

An attempt was made to call the method org.springframework.data.mongodb.core.MongoTemplate.(Lcom/mongodb/Mongo;Ljava/lang/String;)V but it does not exist. Its class, org.springframework.data.mongodb.core.MongoTemplate, is available from the following locations:

file:/C:/Users/npatil/.m2/repository/org/springframework/data/spring-data-mongodb/2.1.2.RELEASE/spring-data-mongodb-2.1.2.RELEASE.jar!/org/springframework/data/mongodb/core/MongoTemplate.class

It was loaded from the following location:

file:/C:/Users/npatil/.m2/repository/org/springframework/data/spring-data-mongodb/2.1.2.RELEASE/spring-data-mongodb-2.1.2.RELEASE.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.mongodb.core.MongoTemplate

Below is a snnipet from my pom:

<dependencies>
.
.
  <dependency>
    <groupId>com.github.mongobee</groupId>
    <artifactId>mongobee</artifactId>
    <version>0.13</version>
  </dependency>
  <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>2.1.2.RELEASE</version>
  </dependency>
.
.
</dependencies>

Version of some of the jars that could help are:
spring-data-mongodb : 2.1.2.RELEASE
spring-web : 5.1.2.RELEASE
mongo-java-driver : 3.8.2.RELEASE

Deleted .m2 and did mvn clean install, but even that did not resolve the issue. Any help would be greatly appreciated.

3
  • Try with Spring Boot 2.0.0.RELEASE Commented Dec 3, 2018 at 12:02
  • din't work :( Any specific reason for making it to 2.0.0? Commented Dec 3, 2018 at 12:27
  • There was nothing to do with the boot version. There is a call to constructor new MongoTemplate(MongoClient mongoClient, String databaseName), when I ctrl-click on it, it goes to Object class. This was perhaps some issues with loading of jars. Commented Dec 10, 2018 at 16:28

2 Answers 2

1

Looks like jar is corrupted or missing, check all spring related jar are 4.x or higher version if that doent work then:
Mongobee depends on Spring 4.x jars which may conflicts with Spring boot 2.x

try the below way

  @Bean
  public Mongobee mongobee(){
    Mongobee mongobee = new Mongobee("mongodb://localhost:27017/seed");
    mongobee.setChangeLogsScanPackage(InitialData.class.getPackageName());
            mongobee.setMongoTemplate(template);

    return mongobee;
  }
Sign up to request clarification or add additional context in comments.

Comments

0

You need change Mongobee by Mongock if you use Springboot 2. The syntax is almost the same because the Mongock project is the continuation of the Mongobee project.

Springboot:

@Bean
public SpringBootMongock mongock(ApplicationContext springContext, MongoClient mongoClient) {
  return (SpringBootMongock) new SpringBootMongockBuilder(mongoClient, "yourDbName", "com.package.to.be.scanned.for.changesets")
      .setApplicationContext(springContext) 
      .setLockQuickConfig()
      .build();
}

Spring:

@Bean
public SpringMongock mongock() {
  MongoClient mongoclient = new MongoClient(new MongoClientURI("yourDbName", yourMongoClientBuilder));
  return new SpringMongockBuilder(mongoclient, "yourDbName", "com.package.to.be.scanned.for.changesets")
      .setLockQuickConfig()
      .build();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.