我正在使用一个带有juste 2存储库的简单Spring Boot 2项目来解决这个问题
https://github.com/mmaryo/spring-boot-2-mongo-dbref-example
@Test
public void testMongoDbRef() {
AccountEntity account = new AccountEntity();
account.setName("Github");
account = accountRepository.save(account).block();
CustomerEntity customer = new CustomerEntity();
customer.setFirstName("Victor");
customer.setLastName("Hugo");
customer.setAccount(account);
customerRepository.save(customer).block();
}
此代码抛出此错误:
引起:java.lang.TypeNotPresentException:输入com.mongodb.reactivestreams.client.MongoClient不存在 引起:java.lang.ClassNotFoundException:com.mongodb.reactivestreams.client.MongoClient
我使用的是mongo v3.4.3
您有解决此问题的想法吗?
答案 0 :(得分:2)
您需要添加Reactive Streams MongoDB驱动程序,使用spring-boot-starter-data-mongodb-reactive
作为启动器(而不是spring-boot-starter-data-mongodb
)。
已解决的依赖关系是:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-async</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-reactivestreams</artifactId>
</dependency>