From f147efb289bd37f1d1c001f3c3ccd6a3e8eeb61f Mon Sep 17 00:00:00 2001 From: Ramnivas Laddad Date: Thu, 8 May 2014 08:04:27 -0700 Subject: [PATCH] Fix compatibility with spring-data-mongodb 1.2.x and 1.3.x --- .../document/MongoDbFactoryCreator.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java b/spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java index c4181c8..ef301c8 100644 --- a/spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java +++ b/spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java @@ -1,5 +1,8 @@ package org.springframework.cloud.service.document; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.UnknownHostException; import org.springframework.cloud.service.AbstractServiceConnectorCreator; @@ -9,9 +12,12 @@ import org.springframework.cloud.service.common.MongoServiceInfo; import org.springframework.data.authentication.UserCredentials; import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.core.SimpleMongoDbFactory; +import org.springframework.util.ClassUtils; +import org.springframework.util.ReflectionUtils; import com.mongodb.MongoClient; import com.mongodb.MongoClientOptions; +import com.mongodb.MongoClientOptions.Builder; import com.mongodb.MongoException; import com.mongodb.ServerAddress; import com.mongodb.WriteConcern; @@ -46,7 +52,25 @@ public class MongoDbFactoryCreator extends AbstractServiceConnectorCreator builderConstructor = ClassUtils.getConstructorIfAvailable(MongoClientOptions.Builder.class); + try { + builder = builderConstructor.newInstance(new Object[0]); + } catch (InstantiationException e) { + throw new IllegalStateException(e); + } catch (IllegalAccessException e) { + throw new IllegalStateException(e); + } catch (IllegalArgumentException e) { + throw new IllegalStateException(e); + } catch (InvocationTargetException e) { + throw new IllegalStateException(e); + } + } if (config != null) { if (config.getConnectionsPerHost() != null) {