简体   繁体   中英

Caused by: java.lang.NoSuchMethodError: org.springframework.data.mongodb.core.MongoTemplate.<init>(Lcom/mongodb/Mongo;Ljava/lang/String;)V

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.

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;
  }

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();
}

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.

Related Question java.lang.NoSuchMethodError: com.mongodb.MongoClient.<init>(Ljava/util/List;Lcom/mongodb/MongoCredential;Lcom/mongodb/MongoClientOptions;)V] java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V Caused by: java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.path()[Ljava/lang/String; Caused by: java.lang.NoSuchMethodError: org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(Ljava/lang/String;)V Caused by: java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.get(Ljava/lang/String;)Ljava/lang/Object java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava/lang/String;)V Getting java.lang.NoSuchMethodError: org.springframework.cglib.core.ReflectUtils.defineClass while inserting data in mongo using Spring MongoTemplate java.lang.NoSuchMethodError: org.springframework.core.GenericTypeResolver.resolveTypeArguments(Ljava/lang/Class;Ljava/lang/Class;) HERE map:Caused by: java.lang.NoSuchMethodError: no non-static method “Ljava/lang/AssertionError;.<init>(Ljava/lang/String;)V” java.lang.NoSuchMethodError:org.quartz.Scheduler.deleteTrigger(Ljava/lang/String;Ljava/lang/String;)V
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM