嗨,我有这个配置文件来连接到我的远程mongodb
服务,现在我需要同时连接1个数据库,但我不知道有人能帮我什么忙?
@Configuration
public class MongoConfig{
@Bean
public MongoDbFactory mongoDbFactory(){
MongoClientURI uri = new MongoClientURI("mongodb://user:pass@localhost:27017/?authSource=admin");
return new SimpleMongoDbFactory(new MongoClient(uri), "DataBuild");
}
@Bean
public MongoOperations mongoOperations(){
return new MongoTemplate(mongoDbFactory());
}
@Bean
MongoTransactionManager transactionManager(MongoDbFactory dbFactory) {
return new MongoTransactionManager(dbFactory);
}
}
1条答案
按热度按时间k2fxgqgv1#
看一下this tutorial,下面是它们使用的
@Configuration
类: