org.springframework.data.mongodb.core.MongoDbFactorySupport Java Examples

The following examples show how to use org.springframework.data.mongodb.core.MongoDbFactorySupport. 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: BeihuMongoDataAutoConfiguration.java    From beihu-boot with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(MongoDbFactory.class)
public MongoDbFactorySupport<?> mongoDbFactory(ObjectProvider<MongoClient> mongo,
		ObjectProvider<com.mongodb.client.MongoClient> mongoClient) {
	MongoClient preferredClient = mongo.getIfAvailable();
	if (preferredClient != null) {
		return new SimpleMongoDbFactory(preferredClient,
				this.beihuMongoProperties.getMongoClientDatabase());
	}
	com.mongodb.client.MongoClient fallbackClient = mongoClient.getIfAvailable();
	if (fallbackClient != null) {
		return new SimpleMongoClientDbFactory(fallbackClient,
				this.beihuMongoProperties.getMongoClientDatabase());
	}
	throw new IllegalStateException("Expected to find at least one MongoDB client.");
}
 
Example #2
Source File: CustomMongoHealthIndicator.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
static MongoClient getMongoClient(SimpleMongoDbFactory mongoClient) {
    try {
        Method privateMethod = MongoDbFactorySupport.class.getDeclaredMethod("getMongoClient", null);
        privateMethod.setAccessible(true);
        return (MongoClient) privateMethod.invoke(mongoClient);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}