org.springframework.data.mongodb.core.MongoTemplate.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中org.springframework.data.mongodb.core.MongoTemplate.<init>()方法的一些代码示例,展示了MongoTemplate.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoTemplate.<init>()方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.MongoTemplate
类名称:MongoTemplate
方法名:<init>

MongoTemplate.<init>介绍

[英]Constructor used for a basic template configuration.
[中]用于基本模板配置的构造函数。

代码示例

代码示例来源:origin: ityouknow/spring-boot-examples

@Primary
@Bean(name = PrimaryMongoConfig.MONGO_TEMPLATE)
public MongoTemplate primaryMongoTemplate() throws Exception {
  return new MongoTemplate(primaryFactory(this.mongoProperties.getPrimary()));
}

代码示例来源:origin: ityouknow/spring-boot-examples

@Bean
@Qualifier(SecondaryMongoConfig.MONGO_TEMPLATE)
public MongoTemplate secondaryMongoTemplate() throws Exception {
  return new MongoTemplate(secondaryFactory(this.mongoProperties.getSecondary()));
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Creates a new {@link DefaultIndexOperations}.
 *
 * @param mongoDbFactory must not be {@literal null}.
 * @param collectionName must not be {@literal null}.
 * @param queryMapper must not be {@literal null}.
 * @param type Type used for mapping potential partial index filter expression. Can be {@literal null}.
 * @since 1.10
 * @deprecated since 2.1. Please use
 *             {@link DefaultIndexOperations#DefaultIndexOperations(MongoOperations, String, Class)}.
 */
@Deprecated
public DefaultIndexOperations(MongoDbFactory mongoDbFactory, String collectionName, QueryMapper queryMapper,
    @Nullable Class<?> type) {
  Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null!");
  Assert.notNull(collectionName, "Collection name can not be null!");
  Assert.notNull(queryMapper, "QueryMapper must not be null!");
  this.collectionName = collectionName;
  this.mapper = queryMapper;
  this.type = type;
  this.mongoOperations = new MongoTemplate(mongoDbFactory);
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Creates a {@link MongoTemplate}.
 *
 * @return
 */
@Bean
public MongoTemplate mongoTemplate() throws Exception {
  return new MongoTemplate(mongoDbFactory(), mappingMongoConverter());
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Creates a {@link MongoTemplate}.
 *
 * @return
 */
@Bean
public MongoTemplate mongoTemplate() throws Exception {
  return new MongoTemplate(mongoDbFactory(), mappingMongoConverter());
}

代码示例来源:origin: spring-projects/spring-integration-samples

public static MongoDbFactory prepareMongoFactory(String... additionalCollectionToDrop) throws Exception{
    MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test");
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    template.dropCollection("messages");
    template.dropCollection("data");
    for (String additionalCollection : additionalCollectionToDrop) {
      template.dropCollection(additionalCollection);
    }
    return mongoDbFactory;
  }
}

代码示例来源:origin: yu199195/hmily

try {
  clientFactoryBean.afterPropertiesSet();
  mongoTemplate = new MongoTemplate(Objects.requireNonNull(clientFactoryBean.getObject()),
      dbName);
} catch (Exception e) {

代码示例来源:origin: yu199195/myth

@Bean
@Qualifier("mongoLogService")
@ConditionalOnProperty(prefix = "myth.mongo", name = "userName")
public LogService mongoLogService() {
  MongoClientFactoryBean clientFactoryBean = new MongoClientFactoryBean();
  MongoCredential credential = MongoCredential.createScramSha1Credential(
      env.getProperty("myth.mongo.userName"),
      env.getProperty("myth.mongo.dbName"),
      env.getProperty("myth.mongo.password").toCharArray());
  clientFactoryBean.setCredentials(new MongoCredential[]{credential});
  List<String> urls = Splitter.on(",").trimResults().splitToList(env.getProperty("myth.mongo.url"));
  ServerAddress[] sds = new ServerAddress[urls.size()];
  for (int i = 0; i < sds.length; i++) {
    List<String> adds = Splitter.on(":").trimResults().splitToList(urls.get(i));
    InetSocketAddress address = new InetSocketAddress(adds.get(0), Integer.parseInt(adds.get(1)));
    sds[i] = new ServerAddress(address);
  }
  clientFactoryBean.setReplicaSetSeeds(sds);
  MongoTemplate mongoTemplate = null;
  try {
    clientFactoryBean.afterPropertiesSet();
    mongoTemplate = new MongoTemplate(clientFactoryBean.getObject(), env.getProperty("myth.mongo.dbName"));
  } catch (Exception e) {
    e.printStackTrace();
  }
  return new MongoLogServiceImpl(mongoTemplate);
}

代码示例来源:origin: yu199195/Raincat

@Bean
  @Qualifier("mongoTransactionRecoverService")
  public RecoverTransactionService mongoTransactionRecoverService() {
    MongoClientFactoryBean clientFactoryBean = new MongoClientFactoryBean();
    MongoCredential credential = MongoCredential.createScramSha1Credential(
        env.getProperty("recover.mongo.userName"),
        env.getProperty("recover.mongo.dbName"),
        env.getProperty("recover.mongo.password").toCharArray());
    clientFactoryBean.setCredentials(new MongoCredential[]{credential});
    List<String> urls = Splitter.on(",").trimResults().splitToList(env.getProperty("recover.mongo.url"));
    ServerAddress[] sds = new ServerAddress[urls.size()];
    for (int i = 0; i < sds.length; i++) {
      List<String> adds = Splitter.on(":").trimResults().splitToList(urls.get(i));
      InetSocketAddress address = new InetSocketAddress(adds.get(0), Integer.parseInt(adds.get(1)));
      sds[i] = new ServerAddress(address);
    }
    clientFactoryBean.setReplicaSetSeeds(sds);
    MongoTemplate mongoTemplate = null;
    try {
      clientFactoryBean.afterPropertiesSet();
      mongoTemplate =
          new MongoTemplate(clientFactoryBean.getObject(),
              env.getProperty("recover.mongo.dbName"));
    } catch (Exception e) {
      e.printStackTrace();
    }
    return new MongoRecoverTransactionServiceImpl(mongoTemplate);
  }
}

代码示例来源:origin: yu199195/Raincat

@Override
public void init(final String appName, final TxConfig txConfig) {
  collectionName = RepositoryPathUtils.buildMongoTableName(appName);
  final TxMongoConfig txMongoConfig = txConfig.getTxMongoConfig();
  MongoClientFactoryBean clientFactoryBean = buildMongoClientFactoryBean(txMongoConfig);
  try {
    clientFactoryBean.afterPropertiesSet();
    template = new MongoTemplate(clientFactoryBean.getObject(), txMongoConfig.getMongoDbName());
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: yu199195/hmily

@Override
public void init(final String modelName, final HmilyConfig hmilyConfig) {
  collectionName = RepositoryPathUtils.buildMongoTableName(modelName);
  final HmilyMongoConfig hmilyMongoConfig = hmilyConfig.getHmilyMongoConfig();
  MongoClientFactoryBean clientFactoryBean = buildMongoClientFactoryBean(hmilyMongoConfig);
  try {
    clientFactoryBean.afterPropertiesSet();
    template = new MongoTemplate(Objects.requireNonNull(clientFactoryBean.getObject()), hmilyMongoConfig.getMongoDbName());
  } catch (Exception e) {
    LogUtil.error(LOGGER, "mongo init error please check you config:{}", e::getMessage);
    throw new HmilyRuntimeException(e);
  }
}

代码示例来源:origin: yu199195/myth

@Override
public void init(final String modelName, final MythConfig mythConfig) {
  collectionName = RepositoryPathUtils.buildMongoTableName(modelName);
  final MythMongoConfig tccMongoConfig = mythConfig.getMythMongoConfig();
  MongoClientFactoryBean clientFactoryBean = buildMongoClientFactoryBean(tccMongoConfig);
  try {
    clientFactoryBean.afterPropertiesSet();
    template = new MongoTemplate(clientFactoryBean.getObject(), tccMongoConfig.getMongoDbName());
  } catch (Exception e) {
    throw new MythRuntimeException(e);
  }
}

代码示例来源:origin: spring-projects/spring-integration

/**
 * Configure the MongoDbMetadataStore by provided {@link MongoDbFactory} and
 * collection name
 * @param factory the mongodb factory
 * @param collectionName the collection name where it persists the data
 */
public MongoDbMetadataStore(MongoDbFactory factory, String collectionName) {
  this(new MongoTemplate(factory), collectionName);
}

代码示例来源:origin: kaaproject/kaa

converter.setTypeMapper(new DefaultMongoTypeMapper(null));
mongoTemplate = new MongoTemplate(dbFactory, converter);
mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION);

代码示例来源:origin: spring-projects/spring-integration

@Override
protected void onInit() {
  this.evaluationContext =
        ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
  if (this.mongoTemplate == null) {
    this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter);
  }
  this.initialized = true;
}

代码示例来源:origin: spring-projects/spring-integration

@After
public void cleanUp() throws Exception {
  MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
  MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
  mongoTemplate.dropCollection(COLLECTION_NAME);
}

代码示例来源:origin: spring-projects/spring-integration

protected void cleanupCollections(MongoDbFactory mongoDbFactory, String... additionalCollectionsToDrop) {
  MongoTemplate template = new MongoTemplate(mongoDbFactory);
  template.dropCollection("messages");
  template.dropCollection("configurableStoreMessages");
  template.dropCollection("data");
  for (String additionalCollection : additionalCollectionsToDrop) {
    template.dropCollection(additionalCollection);
  }
}

代码示例来源:origin: spring-projects/spring-integration

@MongoDbAvailable
@Test
public void testConfigureCustomCollection() {
  final String collectionName = "testMetadataStore";
  final MongoDbFactory mongoDbFactory = this.prepareMongoFactory(collectionName);
  final MongoTemplate template = new MongoTemplate(mongoDbFactory);
  store = new MongoDbMetadataStore(template, collectionName);
  testBasics();
}

代码示例来源:origin: spring-projects/spring-integration

@SuppressWarnings("unchecked")
private List<Person> queryMultipleElements(Expression queryExpression) throws Exception {
  MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
  MongoTemplate template = new MongoTemplate(mongoDbFactory);
  template.save(this.createPerson("Manny"), "data");
  template.save(this.createPerson("Moe"), "data");
  template.save(this.createPerson("Jack"), "data");
  MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
  messageSource.setBeanFactory(mock(BeanFactory.class));
  messageSource.afterPropertiesSet();
  return (List<Person>) messageSource.receive().getPayload();
}

代码示例来源:origin: spring-projects/spring-integration

@Before
public void setUp() throws Exception {
  MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
  MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
  mongoTemplate.save(this.createPerson("Artem"), COLLECTION_NAME);
  mongoTemplate.save(this.createPerson("Gary"), COLLECTION_NAME);
  mongoTemplate.save(this.createPerson("Oleg"), COLLECTION_NAME);
  mongoTemplate.save(this.createPerson("Xavi"), COLLECTION_NAME);
}

相关文章