use of org.springframework.boot.autoconfigure.mongo.MongoProperties in project scaffold-clean-architecture by bancolombia.
the class MongoConfig method mongoProperties.
@Bean
public ReactiveMongoClientFactory mongoProperties(MongoDBSecret secret, Environment env) {
MongoProperties properties = new MongoProperties();
properties.setUri(secret.getUri());
List<MongoClientSettingsBuilderCustomizer> list = new ArrayList<>();
list.add(new MongoPropertiesClientSettingsBuilderCustomizer(properties, env));
return new ReactiveMongoClientFactory(list);
}
use of org.springframework.boot.autoconfigure.mongo.MongoProperties in project charon by harvies.
the class MongoAutoConfiguration method postProcessBeanDefinitionRegistry.
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
if (multipleDataSourcesProperties == null) {
return;
}
Map<String, MongoProperties> dataSources = multipleDataSourcesProperties.getDataSources();
for (Map.Entry<String, MongoProperties> stringMongoPropertiesEntry : dataSources.entrySet()) {
String dataSourceName = stringMongoPropertiesEntry.getKey();
MongoProperties mongoProperties = stringMongoPropertiesEntry.getValue();
GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
genericBeanDefinition.setBeanClass(MongoTemplate.class);
genericBeanDefinition.setScope(ConfigurableBeanFactory.SCOPE_SINGLETON);
ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
genericBeanDefinition.setConstructorArgumentValues(constructorArgumentValues);
constructorArgumentValues.addGenericArgumentValue(new SimpleMongoClientDatabaseFactory(mongoProperties.getUri()));
String mongoTemplateBeanName = dataSourceName + "MongoTemplate";
beanDefinitionRegistry.registerBeanDefinition(mongoTemplateBeanName, genericBeanDefinition);
}
}
use of org.springframework.boot.autoconfigure.mongo.MongoProperties in project spring-oxygen by isxcode.
the class FlysqlAutoConfiguration method flysql.
/**
* 初始化flysql factory
*
* @param flysqlProperties configs
* @param jdbcTemplate jdbcTemplate
* @param mongoTemplate mongoTemplate
* @since 0.0.1
*/
@Bean("flysql")
@ConditionalOnClass(FlysqlAutoConfiguration.class)
private Flysql flysql(FlysqlProperties flysqlProperties, @Nullable JdbcTemplate jdbcTemplate, @Nullable MongoTemplate mongoTemplate) {
Map<String, JdbcTemplate> jdbcTemplateMap;
Map<String, MongoTemplate> mongoTemplateMap;
// 集成oracle/mysql/h2数据库
Map<String, DataSourceProperties> dataSourcePropertiesMap = flysqlProperties.getDatasource();
if (dataSourcePropertiesMap == null) {
jdbcTemplateMap = new HashMap<>(1);
} else {
jdbcTemplateMap = new HashMap<>(dataSourcePropertiesMap.size() + 1);
dataSourcePropertiesMap.forEach((k, v) -> jdbcTemplateMap.put(k, new JdbcTemplate(v.initializeDataSourceBuilder().build())));
}
if (jdbcTemplate != null) {
jdbcTemplateMap.put(FlysqlConstants.PRIMARY_DATASOURCE_NAME, jdbcTemplate);
}
// 集成mongodb数据库
Map<String, MongoProperties> mongodbPropertiesMap = flysqlProperties.getMongodb();
if (mongodbPropertiesMap == null) {
mongoTemplateMap = new HashMap<>(1);
} else {
mongoTemplateMap = new HashMap<>(mongodbPropertiesMap.size() + 1);
mongodbPropertiesMap.forEach((k, v) -> {
String connectSetting;
if (v.getUri() == null) {
connectSetting = "mongo://" + v.getUsername() + ":" + String.valueOf(v.getPassword()) + "@" + v.getHost() + ":" + v.getPort() + "/" + v.getDatabase();
} else {
connectSetting = v.getUri();
}
mongoTemplateMap.put(k, new MongoTemplate(new SimpleMongoClientDatabaseFactory(connectSetting)));
});
}
if (mongoTemplate != null) {
mongoTemplateMap.put(FlysqlConstants.PRIMARY_DATASOURCE_NAME, mongoTemplate);
}
// 储存关系型数据库和非关系型数据库
return new Flysql(jdbcTemplateMap, mongoTemplateMap, flysqlProperties);
}
Aggregations