diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java index 3dc054eafae..4eb57d42b96 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java @@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; /** * {@link EnableAutoConfiguration Auto-configuration} for Mongo. @@ -66,9 +65,8 @@ public class MongoAutoConfiguration { } @Bean - MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties, - Environment environment) { - return new MongoPropertiesClientSettingsBuilderCustomizer(properties, environment); + MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties) { + return new MongoPropertiesClientSettingsBuilderCustomizer(properties); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java index 85f129d98c4..4f12bbfcb9a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java @@ -24,7 +24,6 @@ import com.mongodb.MongoCredential; import com.mongodb.ServerAddress; import org.springframework.core.Ordered; -import org.springframework.core.env.Environment; /** * A {@link MongoClientSettingsBuilderCustomizer} that applies properties from a @@ -37,13 +36,10 @@ public class MongoPropertiesClientSettingsBuilderCustomizer implements MongoClie private final MongoProperties properties; - private final Environment environment; - private int order = 0; - public MongoPropertiesClientSettingsBuilderCustomizer(MongoProperties properties, Environment environment) { + public MongoPropertiesClientSettingsBuilderCustomizer(MongoProperties properties) { this.properties = properties; - this.environment = environment; } @Override @@ -59,10 +55,6 @@ public class MongoPropertiesClientSettingsBuilderCustomizer implements MongoClie } private void applyHostAndPort(MongoClientSettings.Builder settings) { - if (getEmbeddedPort() != null) { - settings.applyConnectionString(new ConnectionString("mongodb://localhost:" + getEmbeddedPort())); - return; - } if (this.properties.getUri() != null) { settings.applyConnectionString(new ConnectionString(this.properties.getUri())); return; @@ -98,16 +90,6 @@ public class MongoPropertiesClientSettingsBuilderCustomizer implements MongoClie return (value != null) ? value : defaultValue; } - private Integer getEmbeddedPort() { - if (this.environment != null) { - String localPort = this.environment.getProperty("local.mongo.port"); - if (localPort != null) { - return Integer.valueOf(localPort); - } - } - return null; - } - @Override public int getOrder() { return this.order; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java index 3c7fb8b65bf..d22d0c3a047 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java @@ -38,7 +38,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; -import org.springframework.core.env.Environment; /** * {@link EnableAutoConfiguration Auto-configuration} for Reactive Mongo. @@ -72,9 +71,8 @@ public class MongoReactiveAutoConfiguration { } @Bean - MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties, - Environment environment) { - return new MongoPropertiesClientSettingsBuilderCustomizer(properties, environment); + MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties) { + return new MongoPropertiesClientSettingsBuilderCustomizer(properties); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizerTests.java index ee77d200487..71e1c3c533d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizerTests.java @@ -24,8 +24,6 @@ import com.mongodb.ServerAddress; import org.bson.UuidRepresentation; import org.junit.jupiter.api.Test; -import org.springframework.mock.env.MockEnvironment; - import static org.assertj.core.api.Assertions.assertThat; /** @@ -37,8 +35,6 @@ class MongoPropertiesClientSettingsBuilderCustomizerTests { private final MongoProperties properties = new MongoProperties(); - private final MockEnvironment environment = new MockEnvironment(); - @Test void portCanBeCustomized() { this.properties.setPort(12345); @@ -141,16 +137,6 @@ class MongoPropertiesClientSettingsBuilderCustomizerTests { assertMongoCredential(settings.getCredential(), "user", "secret", "test"); } - @Test - void uriIsIgnoredInEmbeddedMode() { - this.properties.setUri("mongodb://mongo.example.com:1234/mydb"); - this.environment.setProperty("local.mongo.port", "4000"); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(1); - assertServerAddress(allAddresses.get(0), "localhost", 4000); - } - @Test void uriOverridesUsernameAndPassword() { this.properties.setUri("mongodb://127.0.0.1:1234/mydb"); @@ -191,7 +177,7 @@ class MongoPropertiesClientSettingsBuilderCustomizerTests { private MongoClientSettings customizeSettings() { MongoClientSettings.Builder settings = MongoClientSettings.builder(); - new MongoPropertiesClientSettingsBuilderCustomizer(this.properties, this.environment).customize(settings); + new MongoPropertiesClientSettingsBuilderCustomizer(this.properties).customize(settings); return settings.build(); } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc index 28c1324ef18..d483582753a 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc @@ -549,7 +549,7 @@ If that is not what you want, you can disable transaction management for a test [[features.testing.spring-boot-applications.autoconfigured-spring-data-mongodb]] ==== Auto-configured Data MongoDB Tests You can use `@DataMongoTest` to test MongoDB applications. -By default, it configures an in-memory embedded MongoDB (if available), configures a `MongoTemplate`, scans for `@Document` classes, and configures Spring Data MongoDB repositories. +By default, it configures a `MongoTemplate`, scans for `@Document` classes, and configures Spring Data MongoDB repositories. Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataMongoTest` annotation is used. `@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans. (For more about using MongoDB with Spring Boot, see "<>", earlier in this chapter.) @@ -560,6 +560,8 @@ The following class shows the `@DataMongoTest` annotation in use: include::code:MyDataMongoDbTests[] + + [[features.testing.spring-boot-applications.autoconfigured-spring-data-neo4j]] ==== Auto-configured Data Neo4j Tests You can use `@DataNeo4jTest` to test Neo4j applications.