This commit is contained in:
Stephane Nicoll 2016-06-17 14:35:19 +02:00
parent 7b5df365d8
commit bce6bd6594
2 changed files with 6 additions and 8 deletions

View File

@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.mongo;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Collections;
import java.util.List; import java.util.List;
import com.mongodb.MongoClient; import com.mongodb.MongoClient;
@ -209,7 +209,7 @@ public class MongoProperties {
} }
String host = this.host == null ? "localhost" : this.host; String host = this.host == null ? "localhost" : this.host;
int port = determinePort(environment); int port = determinePort(environment);
return new MongoClient(Arrays.asList(new ServerAddress(host, port)), return new MongoClient(Collections.singletonList(new ServerAddress(host, port)),
credentials, options); credentials, options);
} }
// The options and credentials are in the URI // The options and credentials are in the URI

View File

@ -57,7 +57,6 @@ public class MongoAutoConfigurationTests {
assertThat(this.context.getBeanNamesForType(Mongo.class).length).isEqualTo(1); assertThat(this.context.getBeanNamesForType(Mongo.class).length).isEqualTo(1);
} }
@SuppressWarnings("deprecation")
@Test @Test
public void optionsAdded() { public void optionsAdded() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
@ -66,11 +65,10 @@ public class MongoAutoConfigurationTests {
this.context.register(OptionsConfig.class, this.context.register(OptionsConfig.class,
PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertThat(this.context.getBean(Mongo.class).getMongoOptions().getSocketTimeout()) assertThat(this.context.getBean(MongoClient.class).getMongoClientOptions()
.isEqualTo(300); .getSocketTimeout()).isEqualTo(300);
} }
@SuppressWarnings("deprecation")
@Test @Test
public void optionsAddedButNoHost() { public void optionsAddedButNoHost() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
@ -79,8 +77,8 @@ public class MongoAutoConfigurationTests {
this.context.register(OptionsConfig.class, this.context.register(OptionsConfig.class,
PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertThat(this.context.getBean(Mongo.class).getMongoOptions().getSocketTimeout()) assertThat(this.context.getBean(MongoClient.class).getMongoClientOptions()
.isEqualTo(300); .getSocketTimeout()).isEqualTo(300);
} }
@Test @Test