Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b30d4303
Commit
b30d4303
authored
Feb 09, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-8230
parent
48b0f157
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
127 additions
and
115 deletions
+127
-115
pom.xml
spring-boot-autoconfigure/pom.xml
+10
-10
MongoAutoConfiguration.java
...work/boot/autoconfigure/mongo/MongoAutoConfiguration.java
+3
-8
MongoClientFactory.java
...ramework/boot/autoconfigure/mongo/MongoClientFactory.java
+20
-11
MongoProperties.java
...ngframework/boot/autoconfigure/mongo/MongoProperties.java
+0
-9
ReactiveMongoAutoConfiguration.java
...t/autoconfigure/mongo/ReactiveMongoAutoConfiguration.java
+3
-8
ReactiveMongoClientFactory.java
.../boot/autoconfigure/mongo/ReactiveMongoClientFactory.java
+13
-11
EmbeddedMongoAutoConfiguration.java
...figure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
+2
-1
additional-spring-configuration-metadata.json
...es/META-INF/additional-spring-configuration-metadata.json
+6
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+3
-0
ReactiveCityMongoDbRepository.java
...nfigure/data/alt/mongo/ReactiveCityMongoDbRepository.java
+2
-1
ReactiveMongoDataAutoConfigurationTests.java
...e/data/mongo/ReactiveMongoDataAutoConfigurationTests.java
+2
-7
ReactiveMongoRepositoriesAutoConfigurationTests.java
...ongo/ReactiveMongoRepositoriesAutoConfigurationTests.java
+3
-1
MongoClientFactoryTests.java
...ork/boot/autoconfigure/mongo/MongoClientFactoryTests.java
+14
-9
MongoPropertiesTests.java
...mework/boot/autoconfigure/mongo/MongoPropertiesTests.java
+2
-1
ReactiveMongoAutoConfigurationTests.java
...oconfigure/mongo/ReactiveMongoAutoConfigurationTests.java
+12
-8
ReactiveMongoClientFactoryTests.java
.../autoconfigure/mongo/ReactiveMongoClientFactoryTests.java
+17
-17
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+1
-0
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+2
-1
pom.xml
...tarters/spring-boot-starter-data-mongodb-reactive/pom.xml
+10
-10
spring.provides
...godb-reactive/src/main/resources/META-INF/spring.provides
+1
-1
spring.provides
...-data-mongodb/src/main/resources/META-INF/spring.provides
+1
-1
No files found.
spring-boot-autoconfigure/pom.xml
View file @
b30d4303
...
...
@@ -100,16 +100,6 @@
<artifactId>
de.flapdoodle.embed.mongo
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongodb-driver-async
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongodb-driver-reactivestreams
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
javax.cache
</groupId>
<artifactId>
cache-api
</artifactId>
...
...
@@ -309,6 +299,16 @@
<artifactId>
jboss-transaction-spi
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongodb-driver-async
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongodb-driver-reactivestreams
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-jdbc
</artifactId>
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java
View file @
b30d4303
...
...
@@ -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
<
MongoClientOptions
>
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
;
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java
View file @
b30d4303
...
...
@@ -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
();
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java
View file @
b30d4303
...
...
@@ -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
;
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfiguration.java
View file @
b30d4303
...
...
@@ -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
<
MongoClientSettings
>
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
;
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java
View file @
b30d4303
...
...
@@ -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
);
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
View file @
b30d4303
...
...
@@ -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
{
...
...
spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
View file @
b30d4303
...
...
@@ -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"
,
...
...
spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
b30d4303
...
...
@@ -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,\
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/ReactiveCityMongoDbRepository.java
View file @
b30d4303
...
...
@@ -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
<
City
,
Long
>
{
public
interface
ReactiveCityMongoDbRepository
extends
ReactiveCrudRepository
<
City
,
Long
>
{
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoDataAutoConfigurationTests.java
View file @
b30d4303
...
...
@@ -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
);
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveMongoRepositoriesAutoConfigurationTests.java
View file @
b30d4303
...
...
@@ -52,7 +52,9 @@ public class ReactiveMongoRepositoriesAutoConfigurationTests {
@After
public
void
close
()
{
this
.
context
.
close
();
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java
View file @
b30d4303
...
...
@@ -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
<
ServerAddress
>
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
<
ServerAddress
>
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
<
ServerAddress
>
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
<
ServerAddress
>
extractServerAddresses
(
MongoClient
client
)
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java
View file @
b30d4303
...
...
@@ -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
())
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoAutoConfigurationTests.java
View file @
b30d4303
...
...
@@ -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
()
.
get
SocketSettings
().
get
ReadTimeout
(
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
();
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java
View file @
b30d4303
...
...
@@ -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
<
ServerAddress
>
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
<
ServerAddress
>
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
<
ServerAddress
>
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
<
ServerAddress
>
extractServerAddresses
(
MongoClient
client
)
{
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
b30d4303
...
...
@@ -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.
...
...
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
b30d4303
...
...
@@ -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`'.
...
...
spring-boot-starters/spring-boot-starter-data-mongodb-reactive/pom.xml
View file @
b30d4303
...
...
@@ -23,6 +23,16 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-mongodb
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongo-java-driver
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongodb-driver
</artifactId>
...
...
@@ -39,15 +49,5 @@
<groupId>
io.projectreactor
</groupId>
<artifactId>
reactor-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-mongodb
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongo-java-driver
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
spring-boot-starters/spring-boot-starter-data-mongodb-reactive/src/main/resources/META-INF/spring.provides
View file @
b30d4303
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
spring-boot-starters/spring-boot-starter-data-mongodb/src/main/resources/META-INF/spring.provides
View file @
b30d4303
provides: spring-data-mongodb
\ No newline at end of file
provides: spring-data-mongodb,mongodb-driver
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment