DATAMONGO-1631 - Better method names for reactive configuration support.
This commit renames methods in AbstractReactiveMongoConfiguration for methods exposing MongoClient and ReactiveMongoDatabaseFactory instances. Renaming prevents possible clashes with beans created via AbstractMongoConfiguration (blocking driver) as bean names default to the producing method name. Original Pull Request: #490
This commit is contained in:
committed by
Christoph Strobl
parent
2d21b04a12
commit
3ab3dab2b4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-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.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.mongodb.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -21,9 +20,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
||||
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||
|
||||
import com.mongodb.reactivestreams.client.MongoClient;
|
||||
@@ -39,12 +38,12 @@ import com.mongodb.reactivestreams.client.MongoClient;
|
||||
public abstract class AbstractReactiveMongoConfiguration extends MongoConfigurationSupport {
|
||||
|
||||
/**
|
||||
* Return the {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want to expose a
|
||||
* Return the Reactive Streams {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want to expose a
|
||||
* {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract MongoClient mongoClient();
|
||||
public abstract MongoClient reactiveMongoClient();
|
||||
|
||||
/**
|
||||
* Creates a {@link ReactiveMongoTemplate}.
|
||||
@@ -53,30 +52,29 @@ public abstract class AbstractReactiveMongoConfiguration extends MongoConfigurat
|
||||
*/
|
||||
@Bean
|
||||
public ReactiveMongoOperations reactiveMongoTemplate() throws Exception {
|
||||
return new ReactiveMongoTemplate(mongoDbFactory(), mappingMongoConverter());
|
||||
return new ReactiveMongoTemplate(reactiveMongoDbFactory(), mappingMongoConverter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link Mongo} instance
|
||||
* configured in {@link #mongoClient()}.
|
||||
* configured in {@link #reactiveMongoClient()}.
|
||||
*
|
||||
* @see #mongoClient()
|
||||
* @see #reactiveMongoClient()
|
||||
* @see #reactiveMongoTemplate()
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Bean
|
||||
public ReactiveMongoDatabaseFactory mongoDbFactory() {
|
||||
return new SimpleReactiveMongoDatabaseFactory(mongoClient(), getDatabaseName());
|
||||
public ReactiveMongoDatabaseFactory reactiveMongoDbFactory() {
|
||||
return new SimpleReactiveMongoDatabaseFactory(reactiveMongoClient(), getDatabaseName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
|
||||
* Creates a {@link MappingMongoConverter} using the configured {@link #reactiveMongoDbFactory()} and
|
||||
* {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
|
||||
*
|
||||
* @see #customConversions()
|
||||
* @see #mongoMappingContext()
|
||||
* @see #mongoDbFactory()
|
||||
* @see #reactiveMongoDbFactory()
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
@@ -54,7 +54,7 @@ public class AbstractReactiveMongoConfigurationIntegrationTests {
|
||||
static class ReactiveConfiguration extends AbstractReactiveMongoConfiguration {
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
public MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.mongodb.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@@ -158,7 +157,7 @@ public class AbstractReactiveMongoConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
public MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create();
|
||||
}
|
||||
|
||||
@@ -186,7 +185,7 @@ public class AbstractReactiveMongoConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
public MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DefaultReactiveIndexOperationsTests {
|
||||
static class Config extends AbstractReactiveMongoConfiguration {
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
public MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ReactiveMongoTemplateCollationTests {
|
||||
static class Config extends AbstractReactiveMongoConfiguration {
|
||||
|
||||
@Override
|
||||
public com.mongodb.reactivestreams.client.MongoClient mongoClient() {
|
||||
public com.mongodb.reactivestreams.client.MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ class ApplicationConfig extends AbstractReactiveMongoConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
public MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create();
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public class AppConfig {
|
||||
/*
|
||||
* Use the Reactive Streams Mongo Client API to create a com.mongodb.reactivestreams.client.MongoClient instance.
|
||||
*/
|
||||
public @Bean MongoClient mongoClient() {
|
||||
public @Bean MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create("mongodb://localhost");
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ To register a `ReactiveMongoDatabaseFactory` instance with the container, you wr
|
||||
@Configuration
|
||||
public class MongoConfiguration {
|
||||
|
||||
public @Bean ReactiveMongoDatabaseFactory mongoDatabaseFactory() {
|
||||
public @Bean ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory() {
|
||||
return new SimpleReactiveMongoDatabaseFactory(MongoClients.create(), "database");
|
||||
}
|
||||
}
|
||||
@@ -275,12 +275,12 @@ To define the username and password create MongoDB connection string and pass it
|
||||
@Configuration
|
||||
public class MongoConfiguration {
|
||||
|
||||
public @Bean ReactiveMongoDatabaseFactory mongoDatabaseFactory() {
|
||||
return new SimpleMongoDbFactory(MongoClients.create("mongodb://joe:secret@localhost"), "database", userCredentials);
|
||||
public @Bean ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory() {
|
||||
return new SimpleReactiveMongoDatabaseFactory(MongoClients.create("mongodb://joe:secret@localhost"), "database");
|
||||
}
|
||||
|
||||
public @Bean ReactiveMongoTemplate reactiveMongoTemplate() {
|
||||
return new ReactiveMongoTemplate(mongoDatabaseFactory());
|
||||
return new ReactiveMongoTemplate(reactiveMongoDatabaseFactory());
|
||||
}
|
||||
}
|
||||
----
|
||||
@@ -318,12 +318,12 @@ You can use Java to create and register an instance of `ReactiveMongoTemplate` a
|
||||
@Configuration
|
||||
public class AppConfig {
|
||||
|
||||
public @Bean MongoClient mongoClient() {
|
||||
public @Bean MongoClient reactiveMongoClient() {
|
||||
return MongoClients.create("mongodb://localhost");
|
||||
}
|
||||
|
||||
public @Bean ReactiveMongoTemplate reactiveMongoTemplate() {
|
||||
return new ReactiveMongoTemplate(mongoClient(), "mydatabase");
|
||||
return new ReactiveMongoTemplate(reactiveMongoClient(), "mydatabase");
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Reference in New Issue
Block a user