Spring Boot多数据源配置(二)MongoDB
@Configuration @EnableMongoRepositories(basePackages = "com.kxlist.statistics.domain.statis", mongoTemplateRef = "statisMongo")public> @Autowired
@Qualifier("statisMongoProperties")
private MongoProperties mongoProperties;
@Primary
@Bean(name = "statisMongo")
public MongoTemplate statisMongoTemplate() throws Exception {
return new MongoTemplate(statisFactory(this.mongoProperties));
}
@Bean
@Primary
public MongoDbFactory statisFactory(MongoProperties mongoProperties) throws Exception {
ServerAddress serverAdress = new ServerAddress(mongoProperties.getUri());
return new SimpleMongoDbFactory(new MongoClient(serverAdress), mongoProperties.getDatabase());
}
}
页:
[1]