diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index f618ce593f9..ff941faba63 100755 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -100,16 +100,6 @@ de.flapdoodle.embed.mongo true - - org.mongodb - mongodb-driver-async - true - - - org.mongodb - mongodb-driver-reactivestreams - true - javax.cache cache-api @@ -309,6 +299,16 @@ jboss-transaction-spi true + + org.mongodb + mongodb-driver-async + true + + + org.mongodb + mongodb-driver-reactivestreams + true + org.springframework spring-jdbc diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java index ec9d17e731d..2774a3d3c5d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java @@ -39,6 +39,7 @@ import org.springframework.core.env.Environment; * @author Oliver Gierke * @author Phillip Webb * @author Mark Paluch + * @author Stephane Nicoll */ @Configuration @ConditionalOnClass(MongoClient.class) @@ -46,22 +47,16 @@ import org.springframework.core.env.Environment; @ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory") public class MongoAutoConfiguration { - private final MongoProperties properties; - private final MongoClientOptions options; - private final Environment environment; - private final MongoClientFactory factory; private MongoClient mongo; public MongoAutoConfiguration(MongoProperties properties, ObjectProvider options, Environment environment) { - this.properties = properties; this.options = options.getIfAvailable(); - this.environment = environment; - this.factory = new MongoClientFactory(properties); + this.factory = new MongoClientFactory(properties, environment); } @PreDestroy @@ -74,7 +69,7 @@ public class MongoAutoConfiguration { @Bean @ConditionalOnMissingBean public MongoClient mongo() throws UnknownHostException { - this.mongo = this.factory.createMongoClient(this.options, this.environment); + this.mongo = this.factory.createMongoClient(this.options); return this.mongo; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java index 941d2832ffe..4acd20772b0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java @@ -33,29 +33,37 @@ import org.springframework.core.env.Environment; /** * A factory for a blocking {@link MongoClient} that applies {@link MongoProperties}. * + * @author Dave Syer + * @author Phillip Webb + * @author Josh Long + * @author Andy Wilkinson + * @author EddĂș MelĂ©ndez + * @author Stephane Nicoll + * @author Nasko Vasilev * @author Mark Paluch * @since 2.0.0 */ public class MongoClientFactory { private final MongoProperties properties; + private final Environment environment; - public MongoClientFactory(MongoProperties properties) { + public MongoClientFactory(MongoProperties properties, Environment environment) { this.properties = properties; + this.environment = environment; } /** - * Creates a {@link MongoClient} using the given {@code options} and - * {@code environment}. If the configured port is zero, the value of the - * {@code local.mongo.port} property retrieved from the {@code environment} is used to + * Creates a {@link MongoClient} using the given {@code options}. If the configured + * port is zero, the value of the {@code local.mongo.port} property is used to * configure the client. * @param options the options - * @param environment the environment * @return the Mongo client * @throws UnknownHostException if the configured host is unknown */ - public MongoClient createMongoClient(MongoClientOptions options, - Environment environment) throws UnknownHostException { + public MongoClient createMongoClient(MongoClientOptions options) + throws UnknownHostException { + if (hasCustomAddress() || hasCustomCredentials()) { if (this.properties.getUri() != null) { throw new IllegalStateException("Invalid mongo configuration, " @@ -75,7 +83,7 @@ public class MongoClientFactory { } String host = this.properties.getHost() == null ? "localhost" : this.properties.getHost(); - int port = determinePort(environment); + int port = determinePort(); return new MongoClient( Collections.singletonList(new ServerAddress(host, port)), credentials, options); @@ -94,13 +102,13 @@ public class MongoClientFactory { && this.properties.getPassword() != null; } - private int determinePort(Environment environment) { + private int determinePort() { if (this.properties.getPort() == null) { return MongoProperties.DEFAULT_PORT; } if (this.properties.getPort() == 0) { - if (environment != null) { - String localPort = environment.getProperty("local.mongo.port"); + if (this.environment != null) { + String localPort = this.environment.getProperty("local.mongo.port"); if (localPort != null) { return Integer.valueOf(localPort); } @@ -118,4 +126,5 @@ public class MongoClientFactory { } return MongoClientOptions.builder(); } + } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java index 4e33decd050..b47cabe29c4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java @@ -135,15 +135,6 @@ public class MongoProperties { this.fieldNamingStrategy = fieldNamingStrategy; } - public void clearPassword() { - if (this.password == null) { - return; - } - for (int i = 0; i < this.password.length; i++) { - this.password[i] = 0; - } - } - public String getUri() { return this.uri; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfiguration.java index 318facb8083..cfcd64a82a1 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfiguration.java @@ -34,6 +34,7 @@ import org.springframework.core.env.Environment; * {@link EnableAutoConfiguration Auto-configuration} for Reactive Mongo. * * @author Mark Paluch + * @author Stephane Nicoll * @since 2.0.0 */ @Configuration @@ -41,22 +42,16 @@ import org.springframework.core.env.Environment; @EnableConfigurationProperties(MongoProperties.class) public class ReactiveMongoAutoConfiguration { - private final MongoProperties properties; - private final MongoClientSettings settings; - private final Environment environment; - private final ReactiveMongoClientFactory factory; private MongoClient mongo; public ReactiveMongoAutoConfiguration(MongoProperties properties, ObjectProvider settings, Environment environment) { - this.properties = properties; this.settings = settings.getIfAvailable(); - this.environment = environment; - this.factory = new ReactiveMongoClientFactory(properties); + this.factory = new ReactiveMongoClientFactory(properties, environment); } @PreDestroy @@ -69,7 +64,7 @@ public class ReactiveMongoAutoConfiguration { @Bean @ConditionalOnMissingBean public MongoClient reactiveStreamsMongoClient() { - this.mongo = this.factory.createMongoClient(this.settings, this.environment); + this.mongo = this.factory.createMongoClient(this.settings); return this.mongo; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java index e32d6da4df3..1a38ce47e40 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java @@ -39,27 +39,29 @@ import org.springframework.core.env.Environment; * A factory for a reactive {@link MongoClient} that applies {@link MongoProperties}. * * @author Mark Paluch + * @author Stephane Nicoll * @since 2.0.0 */ public class ReactiveMongoClientFactory { private final MongoProperties properties; - public ReactiveMongoClientFactory(MongoProperties properties) { + private final Environment environment; + + public ReactiveMongoClientFactory(MongoProperties properties, + Environment environment) { this.properties = properties; + this.environment = environment; } /** - * Creates a {@link MongoClient} using the given {@code options} and - * {@code environment}. If the configured port is zero, the value of the - * {@code local.mongo.port} property retrieved from the {@code environment} is used to + * Creates a {@link MongoClient} using the given {@code options}. If the configured + * port is zero, the value of the {@code local.mongo.port} property is used to * configure the client. * @param settings the settings - * @param environment the environment * @return the Mongo client */ - public MongoClient createMongoClient(MongoClientSettings settings, - Environment environment) { + public MongoClient createMongoClient(MongoClientSettings settings) { if (hasCustomAddress() || hasCustomCredentials()) { if (this.properties.getUri() != null) { throw new IllegalStateException("Invalid mongo configuration, " @@ -79,7 +81,7 @@ public class ReactiveMongoClientFactory { } String host = this.properties.getHost() == null ? "localhost" : this.properties.getHost(); - int port = determinePort(environment); + int port = determinePort(); ClusterSettings clusterSettings = ClusterSettings.builder() .hosts(Collections.singletonList(new ServerAddress(host, port))) .build(); @@ -134,13 +136,13 @@ public class ReactiveMongoClientFactory { && this.properties.getPassword() != null; } - private int determinePort(Environment environment) { + private int determinePort() { if (this.properties.getPort() == null) { return MongoProperties.DEFAULT_PORT; } if (this.properties.getPort() == 0) { - if (environment != null) { - String localPort = environment.getProperty("local.mongo.port"); + if (this.environment != null) { + String localPort = this.environment.getProperty("local.mongo.port"); if (localPort != null) { return Integer.valueOf(localPort); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java index 07166c006c9..d576c1d93d4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java @@ -234,7 +234,8 @@ public class EmbeddedMongoAutoConfiguration { * {@code embeddedMongoServer} bean. */ @Configuration - @ConditionalOnClass({ com.mongodb.reactivestreams.client.MongoClient.class, ReactiveMongoClientFactoryBean.class }) + @ConditionalOnClass({ com.mongodb.reactivestreams.client.MongoClient.class, + ReactiveMongoClientFactoryBean.class }) protected static class EmbeddedReactiveMongoDependencyConfiguration extends ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor { diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index e097896216d..4d7ab3e8942 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -112,6 +112,12 @@ "description": "Enable LDAP repositories.", "defaultValue": true }, + { + "name": "spring.data.mongodb.reactive-repositories.enabled", + "type": "java.lang.Boolean", + "description": "Enable Mongo reactive repositories.", + "defaultValue": true + }, { "name": "spring.data.mongodb.repositories.enabled", "type": "java.lang.Boolean", diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index e4c64257fb6..415bc5c874c 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -41,6 +41,8 @@ org.springframework.boot.autoconfigure.data.ldap.LdapDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\ +org.springframework.boot.autoconfigure.data.mongo.ReactiveMongoDataAutoConfiguration,\ +org.springframework.boot.autoconfigure.data.mongo.ReactiveMongoRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\ @@ -83,6 +85,7 @@ org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoCo org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration,\ org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\ org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\ +org.springframework.boot.autoconfigure.mongo.ReactiveMongoAutoConfiguration,\ org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.springframework.boot.autoconfigure.reactor.core.ReactorCoreAutoConfiguration,\ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/ReactiveCityMongoDbRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/ReactiveCityMongoDbRepository.java index 39ffa8b40da..5ac5d2ec3b4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/ReactiveCityMongoDbRepository.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/ReactiveCityMongoDbRepository.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.data.alt.mongo; import org.springframework.boot.autoconfigure.data.mongo.city.City; import org.springframework.data.repository.reactive.ReactiveCrudRepository; -public interface ReactiveCityMongoDbRepository extends ReactiveCrudRepository { +public interface ReactiveCityMongoDbRepository + extends ReactiveCrudRepository { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoDataAutoConfigurationTests.java index cd20c86f6eb..b9efde7d62d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoDataAutoConfigurationTests.java @@ -17,9 +17,7 @@ package org.springframework.boot.autoconfigure.data.mongo; import org.junit.After; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; @@ -36,9 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class ReactiveMongoDataAutoConfigurationTests { - @Rule - public final ExpectedException thrown = ExpectedException.none(); - private AnnotationConfigApplicationContext context; @After @@ -54,8 +49,8 @@ public class ReactiveMongoDataAutoConfigurationTests { PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, ReactiveMongoAutoConfiguration.class, ReactiveMongoDataAutoConfiguration.class); - assertThat(this.context.getBeanNamesForType(ReactiveMongoTemplate.class).length) - .isEqualTo(1); + assertThat(this.context.getBeanNamesForType(ReactiveMongoTemplate.class)) + .hasSize(1); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoRepositoriesAutoConfigurationTests.java index 0633ad1769d..ea24dad6499 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoRepositoriesAutoConfigurationTests.java @@ -52,7 +52,9 @@ public class ReactiveMongoRepositoriesAutoConfigurationTests { @After public void close() { - this.context.close(); + if (this.context != null) { + this.context.close(); + } } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java index ce455d05c7e..6126d684749 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java @@ -35,7 +35,7 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link MongoClientFactory} via {@link MongoProperties}. + * Tests for {@link MongoClientFactory}. * * @author Phillip Webb * @author Andy Wilkinson @@ -51,7 +51,7 @@ public class MongoClientFactoryTests { public void portCanBeCustomized() throws UnknownHostException { MongoProperties properties = new MongoProperties(); properties.setPort(12345); - MongoClient client = new MongoClientFactory(properties).createMongoClient(null, null); + MongoClient client = createMongoClient(properties); List allAddresses = extractServerAddresses(client); assertThat(allAddresses).hasSize(1); assertServerAddress(allAddresses.get(0), "localhost", 12345); @@ -61,7 +61,7 @@ public class MongoClientFactoryTests { public void hostCanBeCustomized() throws UnknownHostException { MongoProperties properties = new MongoProperties(); properties.setHost("mongo.example.com"); - MongoClient client = new MongoClientFactory(properties).createMongoClient(null, null); + MongoClient client = createMongoClient(properties); List allAddresses = extractServerAddresses(client); assertThat(allAddresses).hasSize(1); assertServerAddress(allAddresses.get(0), "mongo.example.com", 27017); @@ -72,7 +72,7 @@ public class MongoClientFactoryTests { MongoProperties properties = new MongoProperties(); properties.setUsername("user"); properties.setPassword("secret".toCharArray()); - MongoClient client = new MongoClientFactory(properties).createMongoClient(null, null); + MongoClient client = createMongoClient(properties); assertMongoCredential(client.getCredentialsList().get(0), "user", "secret", "test"); } @@ -83,7 +83,7 @@ public class MongoClientFactoryTests { properties.setDatabase("foo"); properties.setUsername("user"); properties.setPassword("secret".toCharArray()); - MongoClient client = new MongoClientFactory(properties).createMongoClient(null, null); + MongoClient client = createMongoClient(properties); assertMongoCredential(client.getCredentialsList().get(0), "user", "secret", "foo"); } @@ -94,7 +94,7 @@ public class MongoClientFactoryTests { properties.setAuthenticationDatabase("foo"); properties.setUsername("user"); properties.setPassword("secret".toCharArray()); - MongoClient client = new MongoClientFactory(properties).createMongoClient(null, null); + MongoClient client = createMongoClient(properties); assertMongoCredential(client.getCredentialsList().get(0), "user", "secret", "foo"); } @@ -104,7 +104,7 @@ public class MongoClientFactoryTests { MongoProperties properties = new MongoProperties(); properties.setUri("mongodb://user:secret@mongo1.example.com:12345," + "mongo2.example.com:23456/test"); - MongoClient client = new MongoClientFactory(properties).createMongoClient(null, null); + MongoClient client = createMongoClient(properties); List allAddresses = extractServerAddresses(client); assertThat(allAddresses).hasSize(2); assertServerAddress(allAddresses.get(0), "mongo1.example.com", 12345); @@ -123,7 +123,7 @@ public class MongoClientFactoryTests { this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Invalid mongo configuration, " + "either uri or host/port/credentials must be specified"); - new MongoClientFactory(properties).createMongoClient(null, null); + createMongoClient(properties); } @Test @@ -135,7 +135,12 @@ public class MongoClientFactoryTests { this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Invalid mongo configuration, " + "either uri or host/port/credentials must be specified"); - new MongoClientFactory(properties).createMongoClient(null, null); + createMongoClient(properties); + } + + private MongoClient createMongoClient(MongoProperties properties) + throws UnknownHostException { + return new MongoClientFactory(properties, null).createMongoClient(null); } private List extractServerAddresses(MongoClient client) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java index b479c42014d..504e807f8b0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java @@ -78,7 +78,8 @@ public class MongoPropertiesTests { builder.requiredReplicaSetName("testReplicaSetName"); MongoClientOptions options = builder.build(); MongoProperties properties = new MongoProperties(); - MongoClient client = new MongoClientFactory(properties).createMongoClient(options, null); + MongoClient client = new MongoClientFactory(properties, null) + .createMongoClient(options); MongoClientOptions wrapped = client.getMongoClientOptions(); assertThat(wrapped.isAlwaysUseMBeans()).isEqualTo(options.isAlwaysUseMBeans()); assertThat(wrapped.getConnectionsPerHost()) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfigurationTests.java index 36bb7e96a16..bbc8360012e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfigurationTests.java @@ -57,7 +57,8 @@ public class ReactiveMongoAutoConfigurationTests { @Test public void clientExists() { this.context = new AnnotationConfigApplicationContext( - PropertyPlaceholderAutoConfiguration.class, ReactiveMongoAutoConfiguration.class); + PropertyPlaceholderAutoConfiguration.class, + ReactiveMongoAutoConfiguration.class); assertThat(this.context.getBeanNamesForType(MongoClient.class).length).isEqualTo(1); } @@ -67,10 +68,11 @@ public class ReactiveMongoAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.host:localhost"); this.context.register(OptionsConfig.class, - PropertyPlaceholderAutoConfiguration.class, ReactiveMongoAutoConfiguration.class); + PropertyPlaceholderAutoConfiguration.class, + ReactiveMongoAutoConfiguration.class); this.context.refresh(); - assertThat(this.context.getBean(MongoClient.class).getSettings().getSocketSettings() - .getReadTimeout(TimeUnit.SECONDS)).isEqualTo(300); + assertThat(this.context.getBean(MongoClient.class).getSettings() + .getSocketSettings().getReadTimeout(TimeUnit.SECONDS)).isEqualTo(300); } @Test @@ -79,10 +81,11 @@ public class ReactiveMongoAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.uri:mongodb://localhost/test"); this.context.register(OptionsConfig.class, - PropertyPlaceholderAutoConfiguration.class, ReactiveMongoAutoConfiguration.class); + PropertyPlaceholderAutoConfiguration.class, + ReactiveMongoAutoConfiguration.class); this.context.refresh(); - assertThat(this.context.getBean(MongoClient.class).getSettings().getReadPreference()) - .isEqualTo(ReadPreference.nearest()); + assertThat(this.context.getBean(MongoClient.class).getSettings() + .getReadPreference()).isEqualTo(ReadPreference.nearest()); } @Test @@ -91,7 +94,8 @@ public class ReactiveMongoAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.uri:mongodb://localhost/test"); this.context.register(SslOptionsConfig.class, - PropertyPlaceholderAutoConfiguration.class, ReactiveMongoAutoConfiguration.class); + PropertyPlaceholderAutoConfiguration.class, + ReactiveMongoAutoConfiguration.class); this.context.refresh(); MongoClient mongo = this.context.getBean(MongoClient.class); MongoClientSettings settings = mongo.getSettings(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java index 79d84bc9f91..651d733ef25 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java @@ -31,7 +31,7 @@ import org.junit.rules.ExpectedException; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link ReactiveMongoClientFactory} via {@link MongoProperties}. + * Tests for {@link ReactiveMongoClientFactory}. * * @author Mark Paluch */ @@ -44,8 +44,7 @@ public class ReactiveMongoClientFactoryTests { public void portCanBeCustomized() throws UnknownHostException { MongoProperties properties = new MongoProperties(); properties.setPort(12345); - MongoClient client = new ReactiveMongoClientFactory(properties).createMongoClient(null, - null); + MongoClient client = createMongoClient(properties); List allAddresses = extractServerAddresses(client); assertThat(allAddresses).hasSize(1); assertServerAddress(allAddresses.get(0), "localhost", 12345); @@ -55,8 +54,7 @@ public class ReactiveMongoClientFactoryTests { public void hostCanBeCustomized() throws UnknownHostException { MongoProperties properties = new MongoProperties(); properties.setHost("mongo.example.com"); - MongoClient client = new ReactiveMongoClientFactory(properties).createMongoClient(null, - null); + MongoClient client = createMongoClient(properties); List allAddresses = extractServerAddresses(client); assertThat(allAddresses).hasSize(1); assertServerAddress(allAddresses.get(0), "mongo.example.com", 27017); @@ -67,8 +65,7 @@ public class ReactiveMongoClientFactoryTests { MongoProperties properties = new MongoProperties(); properties.setUsername("user"); properties.setPassword("secret".toCharArray()); - MongoClient client = new ReactiveMongoClientFactory(properties).createMongoClient(null, - null); + MongoClient client = createMongoClient(properties); assertMongoCredential(extractMongoCredentials(client).get(0), "user", "secret", "test"); } @@ -79,9 +76,9 @@ public class ReactiveMongoClientFactoryTests { properties.setDatabase("foo"); properties.setUsername("user"); properties.setPassword("secret".toCharArray()); - MongoClient client = new ReactiveMongoClientFactory(properties).createMongoClient(null, - null); - assertMongoCredential(extractMongoCredentials(client).get(0), "user", "secret", "foo"); + MongoClient client = createMongoClient(properties); + assertMongoCredential(extractMongoCredentials(client).get(0), "user", "secret", + "foo"); } @Test @@ -90,9 +87,9 @@ public class ReactiveMongoClientFactoryTests { properties.setAuthenticationDatabase("foo"); properties.setUsername("user"); properties.setPassword("secret".toCharArray()); - MongoClient client = new ReactiveMongoClientFactory(properties).createMongoClient(null, - null); - assertMongoCredential(extractMongoCredentials(client).get(0), "user", "secret", "foo"); + MongoClient client = createMongoClient(properties); + assertMongoCredential(extractMongoCredentials(client).get(0), "user", "secret", + "foo"); } @Test @@ -100,8 +97,7 @@ public class ReactiveMongoClientFactoryTests { MongoProperties properties = new MongoProperties(); properties.setUri("mongodb://user:secret@mongo1.example.com:12345," + "mongo2.example.com:23456/test"); - MongoClient client = new ReactiveMongoClientFactory(properties).createMongoClient(null, - null); + MongoClient client = createMongoClient(properties); List allAddresses = extractServerAddresses(client); assertThat(allAddresses).hasSize(2); assertServerAddress(allAddresses.get(0), "mongo1.example.com", 12345); @@ -120,7 +116,7 @@ public class ReactiveMongoClientFactoryTests { this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Invalid mongo configuration, " + "either uri or host/port/credentials must be specified"); - new MongoClientFactory(properties).createMongoClient(null, null); + createMongoClient(properties); } @Test @@ -132,7 +128,11 @@ public class ReactiveMongoClientFactoryTests { this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Invalid mongo configuration, " + "either uri or host/port/credentials must be specified"); - new MongoClientFactory(properties).createMongoClient(null, null); + createMongoClient(properties); + } + + private MongoClient createMongoClient(MongoProperties properties) { + return new ReactiveMongoClientFactory(properties, null).createMongoClient(null); } private List extractServerAddresses(MongoClient client) { diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 842c9b33e0e..f2e5cf28be6 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -589,6 +589,7 @@ content into your application; rather pick only the properties that you need. spring.data.mongodb.host=localhost # Mongo server host. Cannot be set with uri. spring.data.mongodb.password= # Login password of the mongo server. Cannot be set with uri. spring.data.mongodb.port=27017 # Mongo server port. Cannot be set with uri. + spring.data.mongodb.reactive-repositories.enabled=true # Enable Mongo reactive repositories. spring.data.mongodb.repositories.enabled=true # Enable Mongo repositories. spring.data.mongodb.uri=mongodb://localhost/test # Mongo database URI. Cannot be set with host, port and credentials. spring.data.mongodb.username= # Login user of the mongo server. Cannot be set with uri. diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index c76b67afb61..33b22b2cb18 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -3299,7 +3299,8 @@ pooled connection factory by default. http://www.mongodb.com/[MongoDB] is an open-source NoSQL document database that uses a JSON-like schema instead of traditional table-based relational data. Spring Boot offers several conveniences for working with MongoDB, including the -`spring-boot-starter-data-mongodb` '`Starter`'. +`spring-boot-starter-data-mongodb` and `spring-boot-starter-data-mongodb-reactive` +'`Starters`'. diff --git a/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/pom.xml b/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/pom.xml index d764fef5606..258f03e19bb 100644 --- a/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/pom.xml +++ b/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/pom.xml @@ -23,6 +23,16 @@ org.springframework.boot spring-boot-starter + + org.springframework.data + spring-data-mongodb + + + org.mongodb + mongo-java-driver + + + org.mongodb mongodb-driver @@ -39,15 +49,5 @@ io.projectreactor reactor-core - - org.springframework.data - spring-data-mongodb - - - org.mongodb - mongo-java-driver - - - diff --git a/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/src/main/resources/META-INF/spring.provides b/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/src/main/resources/META-INF/spring.provides index b19ad47d075..60fce3513b1 100644 --- a/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/src/main/resources/META-INF/spring.provides +++ b/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/src/main/resources/META-INF/spring.provides @@ -1 +1 @@ -provides: spring-data-mongodb-reactive \ No newline at end of file +provides: spring-data-mongodb,mongodb-driver-async,mongodb-driver-reactivestreams \ No newline at end of file diff --git a/spring-boot-starters/spring-boot-starter-data-mongodb/src/main/resources/META-INF/spring.provides b/spring-boot-starters/spring-boot-starter-data-mongodb/src/main/resources/META-INF/spring.provides index c7406f4ec61..14fde4c65bf 100644 --- a/spring-boot-starters/spring-boot-starter-data-mongodb/src/main/resources/META-INF/spring.provides +++ b/spring-boot-starters/spring-boot-starter-data-mongodb/src/main/resources/META-INF/spring.provides @@ -1 +1 @@ -provides: spring-data-mongodb \ No newline at end of file +provides: spring-data-mongodb,mongodb-driver \ No newline at end of file