org.springframework.boot.autoconfigure.mongo.MongoProperties Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.mongo.MongoProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveMongoDsl.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(GenericApplicationContext context) {
	super.initialize(context);
	this.dsl.accept(this);
	if (properties.getUri() == null) {
		properties.setUri(MongoProperties.DEFAULT_URI);
	}
	new MongoDataInitializer(properties).initialize(context);
	new MongoReactiveDataInitializer(properties).initialize(context);
	new MongoReactiveInitializer(properties, embedded).initialize(context);
}
 
Example #2
Source File: NewsServiceApp.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Bean
MongoClient mongoClient(MongoProperties properties) {
    ConnectionString connectionString = new ConnectionString(properties.determineUri());
    MongoClientSettings.Builder builder = MongoClientSettings
            .builder()
            .streamFactoryFactory(NettyStreamFactory::new)
            .applyToClusterSettings(b -> b.applyConnectionString(connectionString))
            .applyToConnectionPoolSettings(b -> b.applyConnectionString(connectionString))
            .applyToServerSettings(b -> b.applyConnectionString(connectionString))
            .applyToSslSettings(b -> b.applyConnectionString(connectionString))
            .applyToSocketSettings(b -> b.applyConnectionString(connectionString))
            .codecRegistry(fromRegistries(
                MongoClients.getDefaultCodecRegistry(),
                fromProviders(PojoCodecProvider.builder()
                                               .automatic(true)
                                               .register(News.class)
                                               .build())
            ));

    if (connectionString.getReadPreference() != null) {
        builder.readPreference(connectionString.getReadPreference());
    }
    if (connectionString.getReadConcern() != null) {
        builder.readConcern(connectionString.getReadConcern());
    }
    if (connectionString.getWriteConcern() != null) {
        builder.writeConcern(connectionString.getWriteConcern());
    }
    if (connectionString.getApplicationName() != null) {
        builder.applicationName(connectionString.getApplicationName());
    }
    return MongoClients.create(builder.build());
}
 
Example #3
Source File: MongeezAutoConfiguration.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
private void copyMissingProperties(MongoProperties mongoProperties, MongeezProperties mongeezProperties) {
    if (StringUtils.isEmpty(mongeezProperties.getDatabase())) {
        mongeezProperties.setDatabase(mongoProperties.getMongoClientDatabase());
    }
    if (StringUtils.isEmpty(mongeezProperties.getAuthenticationDatabase())) {
        mongeezProperties.setAuthenticationDatabase(mongoProperties.getAuthenticationDatabase());
    }
    if (!mongeezProperties.hasCredentials() && hasCredentials(mongoProperties)) {
        // cannot copy credentials because Spring Data MongoDB clears the password after using it
        String msg = "Found credentials for Spring Data MongoDB but no credentials for Mongeez. " +
                "You need to define both for authentication to work.";
        throw new BeanCreationException(msg);
    }
}
 
Example #4
Source File: EmbeddedMongoInitializer.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
public EmbeddedMongoInitializer(MongoProperties mongoProperties, EmbeddedMongoProperties embeddedProperties) {
	this.properties = mongoProperties;
	this.embeddedProperties = embeddedProperties;
}
 
Example #5
Source File: MongoReactiveDataInitializer.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
public MongoReactiveDataInitializer(MongoProperties properties) {
	this.properties = properties;
}
 
Example #6
Source File: MongoDataInitializer.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
public MongoDataInitializer(MongoProperties properties) {
	this.properties = properties;
}
 
Example #7
Source File: ReactiveMongoDsl.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
EmbeddedMongoDsl(MongoProperties properties, Consumer<EmbeddedMongoDsl> dsl) {
	this.dsl = dsl;
	this.mongoProperties = properties;
}
 
Example #8
Source File: MongoConfiguration.java    From webFluxTemplate with MIT License 4 votes vote down vote up
@Autowired
public MongoConfiguration(MongoProperties mongoProperties) {
    this.mongoProperties = mongoProperties;
}
 
Example #9
Source File: MultipleMongoProperties.java    From canal-mongo with Apache License 2.0 4 votes vote down vote up
public MongoProperties getNaive() {
    return naive;
}
 
Example #10
Source File: MultipleMongoProperties.java    From canal-mongo with Apache License 2.0 4 votes vote down vote up
public void setNaive(MongoProperties naive) {
    this.naive = naive;
}
 
Example #11
Source File: MultipleMongoProperties.java    From canal-mongo with Apache License 2.0 4 votes vote down vote up
public MongoProperties getComplete() {
    return complete;
}
 
Example #12
Source File: MultipleMongoProperties.java    From canal-mongo with Apache License 2.0 4 votes vote down vote up
public void setComplete(MongoProperties complete) {
    this.complete = complete;
}
 
Example #13
Source File: MongeezAutoConfiguration.java    From mongeez-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
private boolean hasCredentials(MongoProperties properties) {
    return properties.getUsername() != null && properties.getPassword() != null;
}
 
Example #14
Source File: MultiMongoProperties.java    From micro-service with MIT License 4 votes vote down vote up
@Primary
@Bean(name="companyMongoProperties")
@ConfigurationProperties(prefix="spring.data.mongodb.company")
public MongoProperties companyMongoProperties() {
    return new MongoProperties();
}
 
Example #15
Source File: MultiMongoProperties.java    From micro-service with MIT License 4 votes vote down vote up
@Bean(name="organizationMongoProperties")
@ConfigurationProperties(prefix="spring.data.mongodb.organization")
public MongoProperties organizationMongoProperties() {
    return new MongoProperties();
}