✅ 操作成功!

Consider defining a bean of type ‘MongoTemplate‘ in your configuration已解决

发布时间:2023-06-12 作者:admin 来源:文学

Consider defining a bean of type ‘MongoTemplate‘ in your configuration已解决

Consider defining a bean of type ‘MongoTemplate‘ in your configuration已解决

原因:在 Spring Boot 1.3版本中,会默认提供一个RestTemplate的实例bean,而在 Spring Boot 1.4以及以后的版本中,这个默认的bean不再提供了,因此我们需要手动创建一个RestTemplate的配置。

解决方法:

@configuration public class config { @Bean public MongoClient mongoClient() { return MongoClients.create("mongodb://study:study@122.168.31.34:27017/course"); } @Bean public MongoTemplate mongoTemplate() { return new MongoTemplate(mongoClient(), "course"); } }

👁️ 阅读量:0