ycvodzf 发表于 2017-12-15 20:34:46

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]
查看完整版本: Spring Boot多数据源配置(二)MongoDB