#264 - Read MongoDB port from local.mongo.port.

Port handling for embedded MongoDB use has changed. Spring Boot no longer writes the port to MongoProperties but updates property sources to provide local.mongo.port so the reactive configuration is required to read local.mongo.port to obtain the port.
This commit is contained in:
Mark Paluch
2017-03-06 11:29:37 +01:00
parent 6ee8c48815
commit b1ffd9cede

View File

@@ -21,10 +21,10 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration;
import org.springframework.data.mongodb.core.mapping.event.LoggingEventListener;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
@@ -44,7 +44,7 @@ import com.mongodb.reactivestreams.client.MongoClients;
@RequiredArgsConstructor
class ApplicationConfiguration extends AbstractReactiveMongoConfiguration {
private final MongoProperties mongoProperties;
private final Environment environment;
@Bean
public LoggingEventListener mongoEventListener() {
@@ -55,7 +55,8 @@ class ApplicationConfiguration extends AbstractReactiveMongoConfiguration {
@Bean
@DependsOn("embeddedMongoServer")
public MongoClient mongoClient() {
return MongoClients.create(String.format("mongodb://localhost:%d", mongoProperties.getPort()));
int port = environment.getProperty("local.mongo.port", Integer.class);
return MongoClients.create(String.format("mongodb://localhost:%d", port));
}
@Override