考虑在您的配置中定义类型为 'org.springframework.data.mongodb.core.MongoTemplate' 的 bean
Consider defining a bean of type 'org.springframework.data.mongodb.core.MongoTemplate' in your configuration
我想问一下为什么这段代码在 2.3.0.RELEASE
而不是 Spring 的 2.0.6.RELEASE
数据 MongoDB:
中抛出错误
@Service
public class ServiceX {
@Autowired private MongoTemplate mongoTemplate;
@Scheduled(fixedDelay = 1000) public void scheduled() {
// I am using mongoTemplate here
}
}
MongoTemplate
是命令式变体。您应该改用 ReactiveMongoTemplate
,因为您使用的是 Reactive MongoDB。它曾经在旧版本中工作,但不适用于 Spring Boot 2.3.0.RELASE
及更高版本。
事实上,我昨天创建了这个问题:
您始终可以使用 spring-boot-starter-data-mongodb
而不是 spring-boot-starter-data-mongodb-reactive
来切换到 Spring 数据 MongoDB 的非反应性变体。
我想问一下为什么这段代码在 2.3.0.RELEASE
而不是 Spring 的 2.0.6.RELEASE
数据 MongoDB:
@Service
public class ServiceX {
@Autowired private MongoTemplate mongoTemplate;
@Scheduled(fixedDelay = 1000) public void scheduled() {
// I am using mongoTemplate here
}
}
MongoTemplate
是命令式变体。您应该改用 ReactiveMongoTemplate
,因为您使用的是 Reactive MongoDB。它曾经在旧版本中工作,但不适用于 Spring Boot 2.3.0.RELASE
及更高版本。
事实上,我昨天创建了这个问题:
您始终可以使用 spring-boot-starter-data-mongodb
而不是 spring-boot-starter-data-mongodb-reactive
来切换到 Spring 数据 MongoDB 的非反应性变体。