Spring data / mongoDB - NoSuchMethodError:com.mongodb.DBRef

时间:2017-10-11 07:48:27

标签: mongodb spring-data

我在项目中使用此依赖项:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
    <version>1.5.1.RELEASE</version>
</dependency>

并且有了这种依赖性,mongoDB潜水员的文物在我的项目中:

mongodb-driver-3.4.1.jar and
mongodb-driver.core-3.4.1.jar

两者都有一个包 com.mongodb 。 我得到以下异常:

nested exception is java.lang.NoSuchMethodError: com.mongodb.DBRef.<init>(Lcom/mongodb/DB;Ljava/lang/String;Ljava/lang/Object;)V

有谁知道我做错了什么?

这是我的收藏:

import org.springframework.data.annotation.Id;

import org.springframework.data.mongodb.core.mapping.DBRef; import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "MyCollection")
public class MyCollection {

@Id
private String id;
@DBRef
private User user;

}

Spring-boot-starter-data-mongodb

1 个答案:

答案 0 :(得分:0)

旧版驱动程序(<link href="/css/styles.css" rel="stylesheet" />)和新驱动程序(type='text/css')具有相同的程序包(#include <iostream> using namespace std; // Function prototype void exchange(int*, int*, int* Arr[]); int main() { int* Arr = new int[5], i; //Declare Dynamic Array cout << "Enter Number of Elements : " << endl; for (int i = 0; i < 5; i++) //setting all values in the Array to Zero. scanf_s("%d", Arr + i); cout << endl; int a = Arr[3], b = Arr[4]; cout << "The integers before swap : " << endl << endl; cout << "Fourth integer equals : " << Arr[3] << endl; cout << "Fifth integer equals : " << Arr[4] << endl << endl; exchange(&a, &b, &Arr); cout << "The integers after swap : \n" << endl; cout << "Fourth integer equals : " << Arr[3] << endl; cout << "Fifth integer equals : " << Arr[4] << endl; delete[] Arr; //Delete Dynamic Array system("pause"); return 0; } void exchange(int* a, int* b, int* Arr[]) { cout << "Please Enter two new intergers \n" << endl; cin >> *a; cout << endl; cin >> *b; cout << endl; Arr[3] = a; //These are the problem here, when I try *a it doesn't work Arr[4] = b; }

2.x

https://github.com/mongodb/mongo-java-driver/blob/2.14.x/src/main/com/mongodb/DBRef.java#L67

注意第一个参数是3.x,它是2.x驱动程序中的构造函数,并从3.x版本中删除。

所以看起来您的项目仍然引用2.x驱动程序版本。