admin管理员组

文章数量:1794759

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"); } }

本文标签: beandefiningtypeconfigurationMongoTemplate