Use MongoClient consistently

Closes gh-11431
pull/11378/merge
Johnny Lim 7 years ago committed by Stephane Nicoll
parent 9c4e6f247c
commit d2109ddf4d

@ -20,7 +20,6 @@ import java.net.UnknownHostException;
import java.util.Collections;
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.springframework.beans.BeanUtils;
@ -72,7 +71,7 @@ import org.springframework.util.StringUtils;
* @since 1.1.0
*/
@Configuration
@ConditionalOnClass({ Mongo.class, MongoTemplate.class })
@ConditionalOnClass({ MongoClient.class, MongoTemplate.class })
@EnableConfigurationProperties(MongoProperties.class)
@AutoConfigureAfter(MongoAutoConfiguration.class)
public class MongoDataAutoConfiguration {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 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.
@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.data.mongo;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -52,7 +52,7 @@ import org.springframework.data.mongodb.repository.support.MongoRepositoryFactor
* @see EnableMongoRepositories
*/
@Configuration
@ConditionalOnClass({ Mongo.class, MongoRepository.class })
@ConditionalOnClass({ MongoClient.class, MongoRepository.class })
@ConditionalOnMissingBean({ MongoRepositoryFactoryBean.class,
MongoRepositoryConfigurationExtension.class })
@ConditionalOnProperty(prefix = "spring.data.mongodb.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)

@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.MongodExecutable;
@ -77,7 +76,7 @@ import org.springframework.util.Assert;
@Configuration
@EnableConfigurationProperties({ MongoProperties.class, EmbeddedMongoProperties.class })
@AutoConfigureBefore(MongoAutoConfiguration.class)
@ConditionalOnClass({ Mongo.class, MongodStarter.class })
@ConditionalOnClass({ MongoClient.class, MongodStarter.class })
public class EmbeddedMongoAutoConfiguration {
private static final byte[] IP4_LOOPBACK_ADDRESS = { 127, 0, 0, 1 };

@ -20,7 +20,7 @@ import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Set;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
@ -101,8 +101,8 @@ public class MongoDataAutoConfigurationTests {
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class);
this.context.refresh();
MongoTemplate template = this.context.getBean(MongoTemplate.class);
assertThat(template.getConverter().getConversionService().canConvert(Mongo.class,
Boolean.class)).isTrue();
assertThat(template.getConverter().getConversionService()
.canConvert(MongoClient.class, Boolean.class)).isTrue();
}
@Test
@ -210,10 +210,10 @@ public class MongoDataAutoConfigurationTests {
}
private static class MyConverter implements Converter<Mongo, Boolean> {
private static class MyConverter implements Converter<MongoClient, Boolean> {
@Override
public Boolean convert(Mongo source) {
public Boolean convert(MongoClient source) {
return null;
}

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.data.mongo;
import java.util.Set;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.junit.After;
import org.junit.Test;
@ -59,8 +58,7 @@ public class MongoRepositoriesAutoConfigurationTests {
prepareApplicationContext(TestConfiguration.class);
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
Mongo mongo = this.context.getBean(Mongo.class);
assertThat(mongo).isInstanceOf(MongoClient.class);
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1);
MongoMappingContext mappingContext = this.context
.getBean(MongoMappingContext.class);
@SuppressWarnings("unchecked")
@ -72,9 +70,7 @@ public class MongoRepositoriesAutoConfigurationTests {
@Test
public void testNoRepositoryConfiguration() throws Exception {
prepareApplicationContext(EmptyConfiguration.class);
Mongo mongo = this.context.getBean(Mongo.class);
assertThat(mongo).isInstanceOf(MongoClient.class);
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1);
}
@Test

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.mongo;
import javax.net.SocketFactory;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import org.junit.After;
@ -54,7 +53,7 @@ public class MongoAutoConfigurationTests {
public void clientExists() {
this.context = new AnnotationConfigApplicationContext(
PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class);
assertThat(this.context.getBeanNamesForType(Mongo.class).length).isEqualTo(1);
assertThat(this.context.getBeanNamesForType(MongoClient.class)).hasSize(1);
}
@Test

Loading…
Cancel
Save