Merge pull request #3126 from eddumelendez/gh-3105

* gh-3105:
  Remove deprecated SimpleMongoDbFactory call
pull/3245/merge
Phillip Webb 10 years ago
commit 93e6a7171b

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.mongodb.Mongo; import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions; import com.mongodb.MongoClientOptions;
/** /**
@ -39,7 +39,7 @@ import com.mongodb.MongoClientOptions;
* @author Phillip Webb * @author Phillip Webb
*/ */
@Configuration @Configuration
@ConditionalOnClass(Mongo.class) @ConditionalOnClass(MongoClient.class)
@EnableConfigurationProperties(MongoProperties.class) @EnableConfigurationProperties(MongoProperties.class)
@ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory") @ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory")
public class MongoAutoConfiguration { public class MongoAutoConfiguration {
@ -50,7 +50,7 @@ public class MongoAutoConfiguration {
@Autowired(required = false) @Autowired(required = false)
private MongoClientOptions options; private MongoClientOptions options;
private Mongo mongo; private MongoClient mongo;
@PreDestroy @PreDestroy
public void close() { public void close() {
@ -61,7 +61,7 @@ public class MongoAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public Mongo mongo() throws UnknownHostException { public MongoClient mongo() throws UnknownHostException {
this.mongo = this.properties.createMongoClient(this.options); this.mongo = this.properties.createMongoClient(this.options);
return this.mongo; return this.mongo;
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.annotation.Persistent; import org.springframework.data.annotation.Persistent;
import org.springframework.data.authentication.UserCredentials;
import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
@ -60,6 +59,7 @@ import org.springframework.util.StringUtils;
import com.mongodb.DB; import com.mongodb.DB;
import com.mongodb.Mongo; import com.mongodb.Mongo;
import com.mongodb.MongoClient;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's mongo support. * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's mongo support.
@ -74,6 +74,7 @@ import com.mongodb.Mongo;
* @author Oliver Gierke * @author Oliver Gierke
* @author Josh Long * @author Josh Long
* @author Phillip Webb * @author Phillip Webb
* @author Eddú Meléndez
* @since 1.1.0 * @since 1.1.0
*/ */
@Configuration @Configuration
@ -100,15 +101,8 @@ public class MongoDataAutoConfiguration implements BeanClassLoaderAware {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public MongoDbFactory mongoDbFactory(Mongo mongo) throws Exception { public MongoDbFactory mongoDbFactory(MongoClient mongo) throws Exception {
String database = this.properties.getMongoClientDatabase(); 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); return new SimpleMongoDbFactory(mongo, database);
} }

Loading…
Cancel
Save