
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
© 版权声明:本文《Consider defining a bean of type ‘MongoTemplate‘ in your configuration已解决》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686557279a291393.html。