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
f753c319
Commit
f753c319
authored
Jul 10, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Set up MongoClient beans' dependencies by type rather than name"
See gh-16627
parent
39f10394
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
19 deletions
+51
-19
MongoClientDependsOnBeanFactoryPostProcessor.java
...a/mongo/MongoClientDependsOnBeanFactoryPostProcessor.java
+17
-0
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor.java
...eStreamsMongoClientDependsOnBeanFactoryPostProcessor.java
+17
-0
EmbeddedMongoAutoConfiguration.java
...figure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
+9
-17
EmbeddedMongoAutoConfigurationTests.java
...e/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java
+8
-2
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoClientDependsOnBeanFactoryPostProcessor.java
View file @
f753c319
...
@@ -36,8 +36,25 @@ import org.springframework.data.mongodb.core.MongoClientFactoryBean;
...
@@ -36,8 +36,25 @@ import org.springframework.data.mongodb.core.MongoClientFactoryBean;
@Order
(
Ordered
.
LOWEST_PRECEDENCE
)
@Order
(
Ordered
.
LOWEST_PRECEDENCE
)
public
class
MongoClientDependsOnBeanFactoryPostProcessor
extends
AbstractDependsOnBeanFactoryPostProcessor
{
public
class
MongoClientDependsOnBeanFactoryPostProcessor
extends
AbstractDependsOnBeanFactoryPostProcessor
{
/**
* Creates a new {@code MongoClientDependsOnBeanFactoryPostProcessor} that will set up
* dependencies upon beans with the given names.
* @param dependsOn names of the beans to depend upon
* @deprecated since 2.1.7 in favor of
* {@link #MongoClientDependsOnBeanFactoryPostProcessor}
*/
@Deprecated
public
MongoClientDependsOnBeanFactoryPostProcessor
(
String
...
dependsOn
)
{
public
MongoClientDependsOnBeanFactoryPostProcessor
(
String
...
dependsOn
)
{
super
(
MongoClient
.
class
,
MongoClientFactoryBean
.
class
,
dependsOn
);
super
(
MongoClient
.
class
,
MongoClientFactoryBean
.
class
,
dependsOn
);
}
}
/**
* Creates a new {@code MongoClientDependsOnBeanFactoryPostProcessor} that will set up
* dependencies upon beans with the given types.
* @param dependsOn types of the beans to depend upon
*/
public
MongoClientDependsOnBeanFactoryPostProcessor
(
Class
<?>...
dependsOn
)
{
super
(
MongoClient
.
class
,
MongoClientFactoryBean
.
class
,
dependsOn
);
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor.java
View file @
f753c319
...
@@ -37,8 +37,25 @@ import org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean;
...
@@ -37,8 +37,25 @@ import org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean;
public
class
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
public
class
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
extends
AbstractDependsOnBeanFactoryPostProcessor
{
extends
AbstractDependsOnBeanFactoryPostProcessor
{
/**
* Creates a new {@code ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor}
* that will set up dependencies upon beans with the given names.
* @param dependsOn names of the beans to depend upon
* @deprecated since 2.1.7 in favor of
* {@link #ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor}
*/
@Deprecated
public
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
(
String
...
dependsOn
)
{
public
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
(
String
...
dependsOn
)
{
super
(
MongoClient
.
class
,
ReactiveMongoClientFactoryBean
.
class
,
dependsOn
);
super
(
MongoClient
.
class
,
ReactiveMongoClientFactoryBean
.
class
,
dependsOn
);
}
}
/**
* Creates a new {@code ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor}
* that will set up dependencies upon beans with the given types.
* @param dependsOn types of the beans to depend upon
*/
public
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
(
Class
<?>...
dependsOn
)
{
super
(
MongoClient
.
class
,
ReactiveMongoClientFactoryBean
.
class
,
dependsOn
);
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
View file @
f753c319
...
@@ -48,8 +48,6 @@ import de.flapdoodle.embed.process.store.ArtifactStoreBuilder;
...
@@ -48,8 +48,6 @@ 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
;
...
@@ -218,32 +216,26 @@ public class EmbeddedMongoAutoConfiguration {
...
@@ -218,32 +216,26 @@ public class EmbeddedMongoAutoConfiguration {
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
({
MongoClient
.
class
,
MongoClientFactoryBean
.
class
})
@ConditionalOnClass
({
MongoClient
.
class
,
MongoClientFactoryBean
.
class
})
protected
static
class
EmbeddedMongoDependencyConfiguration
{
protected
static
class
EmbeddedMongoDependencyConfiguration
extends
MongoClientDependsOnBeanFactoryPostProcessor
{
@Bean
EmbeddedMongoDependencyConfiguration
()
{
public
MongoClientDependsOnBeanFactoryPostProcessor
mongoClientDependsOnBeanFactoryPostProcessor
(
super
(
MongodExecutable
.
class
);
ListableBeanFactory
listableBeanFactory
)
{
String
[]
mongoExecutableBeanNames
=
BeanFactoryUtils
.
beanNamesForTypeIncludingAncestors
(
listableBeanFactory
,
MongodExecutable
.
class
);
return
new
MongoClientDependsOnBeanFactoryPostProcessor
(
mongoExecutableBeanNames
);
}
}
}
}
/**
/**
* Additional configuration to ensure that {@link MongoClient} beans depend on any
* Additional configuration to ensure that
* {@link com.mongodb.reactivestreams.client.MongoClient} beans depend on any
* {@link MongodExecutable} beans.
* {@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
{
@Bean
EmbeddedReactiveMongoDependencyConfiguration
()
{
public
ReactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
reactiveStreamsMongoClientDependsOnBeanFactoryPostProcessor
(
super
(
MongodExecutable
.
class
);
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 @
f753c319
...
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.mongo.embedded;
...
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.mongo.embedded;
import
java.io.File
;
import
java.io.File
;
import
java.util.EnumSet
;
import
java.util.EnumSet
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
com.mongodb.MongoClient
;
import
com.mongodb.MongoClient
;
...
@@ -33,6 +34,7 @@ import org.junit.After;
...
@@ -33,6 +34,7 @@ import org.junit.After;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration
;
import
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
;
import
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
;
...
@@ -45,7 +47,6 @@ import org.springframework.data.mongodb.core.MongoTemplate;
...
@@ -45,7 +47,6 @@ 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}.
...
@@ -177,7 +178,12 @@ public class EmbeddedMongoAutoConfigurationTests {
...
@@ -177,7 +178,12 @@ public class EmbeddedMongoAutoConfigurationTests {
@Test
@Test
public
void
customMongoServerConfiguration
()
{
public
void
customMongoServerConfiguration
()
{
assertThatCode
(()
->
load
(
CustomMongoConfiguration
.
class
)).
doesNotThrowAnyException
();
load
(
CustomMongoConfiguration
.
class
);
Map
<
String
,
MongoClient
>
mongoClients
=
this
.
context
.
getBeansOfType
(
MongoClient
.
class
);
for
(
String
mongoClientBeanName
:
mongoClients
.
keySet
())
{
BeanDefinition
beanDefinition
=
this
.
context
.
getBeanFactory
().
getBeanDefinition
(
mongoClientBeanName
);
assertThat
(
beanDefinition
.
getDependsOn
()).
contains
(
"customMongoServer"
);
}
}
}
private
void
assertVersionConfiguration
(
String
configuredVersion
,
String
expectedVersion
)
{
private
void
assertVersionConfiguration
(
String
configuredVersion
,
String
expectedVersion
)
{
...
...
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