From 4883a5240a6c6b7d4fd0fca33c1611996e0e2fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Thu, 4 Jun 2015 21:41:10 -0500 Subject: [PATCH] Remove deprecated SimpleMongoDbFactory call Update MongoAutoConfiguration to create a `MongoClient` bean rather than `Mongo` and update `MongoDataAutoConfiguration` to remove the call to the deprecated `SimpleMongoDbFactory`. Fixes gh-3105 Closes gh-3126 --- .../mongo/MongoAutoConfiguration.java | 10 +++++----- .../mongo/MongoDataAutoConfiguration.java | 14 ++++---------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java index a9b011c2dd..18de9523a5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.mongodb.Mongo; +import com.mongodb.MongoClient; import com.mongodb.MongoClientOptions; /** @@ -39,7 +39,7 @@ import com.mongodb.MongoClientOptions; * @author Phillip Webb */ @Configuration -@ConditionalOnClass(Mongo.class) +@ConditionalOnClass(MongoClient.class) @EnableConfigurationProperties(MongoProperties.class) @ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory") public class MongoAutoConfiguration { @@ -50,7 +50,7 @@ public class MongoAutoConfiguration { @Autowired(required = false) private MongoClientOptions options; - private Mongo mongo; + private MongoClient mongo; @PreDestroy public void close() { @@ -61,7 +61,7 @@ public class MongoAutoConfiguration { @Bean @ConditionalOnMissingBean - public Mongo mongo() throws UnknownHostException { + public MongoClient mongo() throws UnknownHostException { this.mongo = this.properties.createMongoClient(this.options); return this.mongo; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.java index 13ebb3d4d6..2300cd6f63 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,6 @@ import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.annotation.Persistent; -import org.springframework.data.authentication.UserCredentials; import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.SimpleMongoDbFactory; @@ -60,6 +59,7 @@ import org.springframework.util.StringUtils; import com.mongodb.DB; import com.mongodb.Mongo; +import com.mongodb.MongoClient; /** * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's mongo support. @@ -74,6 +74,7 @@ import com.mongodb.Mongo; * @author Oliver Gierke * @author Josh Long * @author Phillip Webb + * @author EddĂș MelĂ©ndez * @since 1.1.0 */ @Configuration @@ -100,15 +101,8 @@ public class MongoDataAutoConfiguration implements BeanClassLoaderAware { @Bean @ConditionalOnMissingBean - public MongoDbFactory mongoDbFactory(Mongo mongo) throws Exception { + public MongoDbFactory mongoDbFactory(MongoClient mongo) throws Exception { String database = this.properties.getMongoClientDatabase(); - String authDatabase = this.properties.getAuthenticationDatabase(); - if (StringUtils.hasLength(authDatabase)) { - String username = this.properties.getUsername(); - String password = new String(this.properties.getPassword()); - UserCredentials credentials = new UserCredentials(username, password); - return new SimpleMongoDbFactory(mongo, database, credentials, authDatabase); - } return new SimpleMongoDbFactory(mongo, database); }