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
39f10394
Commit
39f10394
authored
Apr 23, 2019
by
ielatif
Committed by
Andy Wilkinson
Jul 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set up MongoClient beans' dependencies by type rather than name
See gh-16627
parent
1678de73
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
11 deletions
+41
-11
EmbeddedMongoAutoConfiguration.java
...figure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
+21
-11
EmbeddedMongoAutoConfigurationTests.java
...e/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java
+20
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
View file @
39f10394
...
@@ -48,6 +48,8 @@ import de.flapdoodle.embed.process.store.ArtifactStoreBuilder;
...
@@ -48,6 +48,8 @@ import de.flapdoodle.embed.process.store.ArtifactStoreBuilder;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.beans.factory.ListableBeanFactory
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
@@ -74,6 +76,7 @@ import org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean;
...
@@ -74,6 +76,7 @@ import org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean;
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Yogesh Lonkar
* @author Yogesh Lonkar
* @author Mark Paluch
* @author Mark Paluch
* @author Issam El-atif
* @since 1.3.0
* @since 1.3.0
*/
*/
@Configuration
@Configuration
...
@@ -210,30 +213,37 @@ public class EmbeddedMongoAutoConfiguration {
...
@@ -210,30 +213,37 @@ public class EmbeddedMongoAutoConfiguration {
}
}
/**
/**
* Additional configuration to ensure that {@link MongoClient} beans depend on
the
* Additional configuration to ensure that {@link MongoClient} beans depend on
any
* {@
code embeddedMongoServer} bean
.
* {@
link MongodExecutable} beans
.
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
({
MongoClient
.
class
,
MongoClientFactoryBean
.
class
})
@ConditionalOnClass
({
MongoClient
.
class
,
MongoClientFactoryBean
.
class
})
protected
static
class
EmbeddedMongoDependencyConfiguration
extends
MongoClientDependsOnBeanFactoryPostProcessor
{
protected
static
class
EmbeddedMongoDependencyConfiguration
{
public
EmbeddedMongoDependencyConfiguration
()
{
@Bean
super
(
"embeddedMongoServer"
);
public
MongoClientDependsOnBeanFactoryPostProcessor
mongoClientDependsOnBeanFactoryPostProcessor
(
ListableBeanFactory
listableBeanFactory
)
{
String
[]
mongoExecutableBeanNames
=
BeanFactoryUtils
.
beanNamesForTypeIncludingAncestors
(
listableBeanFactory
,
MongodExecutable
.
class
);
return
new
MongoClientDependsOnBeanFactoryPostProcessor
(
mongoExecutableBeanNames
);
}
}
}
}
/**
/**
* Additional configuration to ensure that {@link MongoClient} beans depend on
the
* Additional configuration to ensure that {@link MongoClient} beans depend on
any
* {@
code embeddedMongoServer} bean
.
* {@
link MongodExecutable} beans
.
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
({
com
.
mongodb
.
reactivestreams
.
client
.
MongoClient
.
class
,
ReactiveMongoClientFactoryBean
.
class
})
@ConditionalOnClass
({
com
.
mongodb
.
reactivestreams
.
client
.
MongoClient
.
class
,
ReactiveMongoClientFactoryBean
.
class
})
protected
static
class
EmbeddedReactiveMongoDependencyConfiguration
protected
static
class
EmbeddedReactiveMongoDependencyConfiguration
{
extends
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
{
public
EmbeddedReactiveMongoDependencyConfiguration
()
{
@Bean
super
(
"embeddedMongoServer"
);
public
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
reactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
(
ListableBeanFactory
listableBeanFactory
)
{
String
[]
mongoExecutableBeanNames
=
BeanFactoryUtils
.
beanNamesForTypeIncludingAncestors
(
listableBeanFactory
,
MongodExecutable
.
class
);
return
new
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
(
mongoExecutableBeanNames
);
}
}
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java
View file @
39f10394
...
@@ -22,10 +22,12 @@ import java.util.stream.Collectors;
...
@@ -22,10 +22,12 @@ import java.util.stream.Collectors;
import
com.mongodb.MongoClient
;
import
com.mongodb.MongoClient
;
import
de.flapdoodle.embed.mongo.MongodExecutable
;
import
de.flapdoodle.embed.mongo.MongodExecutable
;
import
de.flapdoodle.embed.mongo.MongodStarter
;
import
de.flapdoodle.embed.mongo.config.IMongodConfig
;
import
de.flapdoodle.embed.mongo.config.IMongodConfig
;
import
de.flapdoodle.embed.mongo.config.Storage
;
import
de.flapdoodle.embed.mongo.config.Storage
;
import
de.flapdoodle.embed.mongo.distribution.Feature
;
import
de.flapdoodle.embed.mongo.distribution.Feature
;
import
de.flapdoodle.embed.mongo.distribution.Version
;
import
de.flapdoodle.embed.mongo.distribution.Version
;
import
de.flapdoodle.embed.process.config.IRuntimeConfig
;
import
org.bson.Document
;
import
org.bson.Document
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -43,6 +45,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
...
@@ -43,6 +45,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import
org.springframework.util.FileSystemUtils
;
import
org.springframework.util.FileSystemUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatCode
;
/**
/**
* Tests for {@link EmbeddedMongoAutoConfiguration}.
* Tests for {@link EmbeddedMongoAutoConfiguration}.
...
@@ -50,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -50,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Henryk Konsek
* @author Henryk Konsek
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Issam El-atif
*/
*/
public
class
EmbeddedMongoAutoConfigurationTests
{
public
class
EmbeddedMongoAutoConfigurationTests
{
...
@@ -171,6 +175,11 @@ public class EmbeddedMongoAutoConfigurationTests {
...
@@ -171,6 +175,11 @@ public class EmbeddedMongoAutoConfigurationTests {
assertThat
(
this
.
context
.
getBean
(
MongodExecutable
.
class
).
isRegisteredJobKiller
()).
isFalse
();
assertThat
(
this
.
context
.
getBean
(
MongodExecutable
.
class
).
isRegisteredJobKiller
()).
isFalse
();
}
}
@Test
public
void
customMongoServerConfiguration
()
{
assertThatCode
(()
->
load
(
CustomMongoConfiguration
.
class
)).
doesNotThrowAnyException
();
}
private
void
assertVersionConfiguration
(
String
configuredVersion
,
String
expectedVersion
)
{
private
void
assertVersionConfiguration
(
String
configuredVersion
,
String
expectedVersion
)
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
"spring.data.mongodb.port=0"
).
applyTo
(
this
.
context
);
TestPropertyValues
.
of
(
"spring.data.mongodb.port=0"
).
applyTo
(
this
.
context
);
...
@@ -216,4 +225,15 @@ public class EmbeddedMongoAutoConfigurationTests {
...
@@ -216,4 +225,15 @@ public class EmbeddedMongoAutoConfigurationTests {
}
}
@Configuration
static
class
CustomMongoConfiguration
{
@Bean
(
initMethod
=
"start"
,
destroyMethod
=
"stop"
)
public
MongodExecutable
customMongoServer
(
IRuntimeConfig
runtimeConfig
,
IMongodConfig
mongodConfig
)
{
MongodStarter
mongodStarter
=
MongodStarter
.
getInstance
(
runtimeConfig
);
return
mongodStarter
.
prepare
(
mongodConfig
);
}
}
}
}
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