Search in sources :

Example 1 with MongoProperties

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);
}
Also used : MongoClientSettingsBuilderCustomizer(org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer) ReactiveMongoClientFactory(org.springframework.boot.autoconfigure.mongo.ReactiveMongoClientFactory) ArrayList(java.util.ArrayList) MongoPropertiesClientSettingsBuilderCustomizer(org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer) MongoProperties(org.springframework.boot.autoconfigure.mongo.MongoProperties) Bean(org.springframework.context.annotation.Bean)

Example 2 with MongoProperties

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);
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) Map(java.util.Map) MongoProperties(org.springframework.boot.autoconfigure.mongo.MongoProperties) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 3 with MongoProperties

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);
}
Also used : Flysql(com.isxcode.oxygen.flysql.core.Flysql) SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) DataSourceProperties(org.springframework.boot.autoconfigure.jdbc.DataSourceProperties) MongoProperties(org.springframework.boot.autoconfigure.mongo.MongoProperties) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) Bean(org.springframework.context.annotation.Bean)

Aggregations

MongoProperties (org.springframework.boot.autoconfigure.mongo.MongoProperties)3 Bean (org.springframework.context.annotation.Bean)2 SimpleMongoClientDatabaseFactory (org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory)2 Flysql (com.isxcode.oxygen.flysql.core.Flysql)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 DataSourceProperties (org.springframework.boot.autoconfigure.jdbc.DataSourceProperties)1 MongoClientSettingsBuilderCustomizer (org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer)1 MongoPropertiesClientSettingsBuilderCustomizer (org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer)1 ReactiveMongoClientFactory (org.springframework.boot.autoconfigure.mongo.ReactiveMongoClientFactory)1 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1