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
1bd1ffdb
Commit
1bd1ffdb
authored
Oct 23, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
34156b21
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
84 deletions
+67
-84
BeanTypeRegistry.java
...mework/boot/autoconfigure/condition/BeanTypeRegistry.java
+23
-23
ConditionalOnMissingBeanTests.java
...utoconfigure/condition/ConditionalOnMissingBeanTests.java
+44
-61
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/BeanTypeRegistry.java
View file @
1bd1ffdb
...
...
@@ -83,27 +83,6 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
this
.
beanFactory
=
beanFactory
;
}
/**
* Factory method to get the {@link BeanTypeRegistry} for a given {@link BeanFactory}.
* @param beanFactory the source bean factory
* @return the {@link BeanTypeRegistry} for the given bean factory
*/
static
BeanTypeRegistry
get
(
ListableBeanFactory
beanFactory
)
{
Assert
.
isInstanceOf
(
DefaultListableBeanFactory
.
class
,
beanFactory
);
DefaultListableBeanFactory
listableBeanFactory
=
(
DefaultListableBeanFactory
)
beanFactory
;
Assert
.
isTrue
(
listableBeanFactory
.
isAllowEagerClassLoading
(),
"Bean factory must allow eager class loading"
);
if
(!
listableBeanFactory
.
containsLocalBean
(
BEAN_NAME
))
{
BeanDefinition
bd
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
BeanTypeRegistry
.
class
,
()
->
new
BeanTypeRegistry
(
(
DefaultListableBeanFactory
)
beanFactory
))
.
getBeanDefinition
();
listableBeanFactory
.
registerBeanDefinition
(
BEAN_NAME
,
bd
);
}
return
listableBeanFactory
.
getBean
(
BEAN_NAME
,
BeanTypeRegistry
.
class
);
}
/**
* Return the names of beans matching the given type (including subclasses), judging
* from either bean definitions or the value of {@link FactoryBean#getObjectType()} in
...
...
@@ -113,7 +92,7 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
* @return the names of beans (or objects created by FactoryBeans) matching the given
* object type (including subclasses), or an empty set if none
*/
Set
<
String
>
getNamesForType
(
Class
<?>
type
)
{
public
Set
<
String
>
getNamesForType
(
Class
<?>
type
)
{
updateTypesIfNecessary
();
return
this
.
beanTypes
.
entrySet
().
stream
()
.
filter
((
entry
)
->
entry
.
getValue
()
!=
null
...
...
@@ -131,7 +110,7 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
* @return the names of beans (or objects created by FactoryBeans) annotated with the
* given annotation, or an empty set if none
*/
Set
<
String
>
getNamesForAnnotation
(
Class
<?
extends
Annotation
>
annotation
)
{
public
Set
<
String
>
getNamesForAnnotation
(
Class
<?
extends
Annotation
>
annotation
)
{
updateTypesIfNecessary
();
return
this
.
beanTypes
.
entrySet
().
stream
()
.
filter
((
entry
)
->
entry
.
getValue
()
!=
null
&&
AnnotationUtils
...
...
@@ -352,4 +331,25 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
return
null
;
}
/**
* Factory method to get the {@link BeanTypeRegistry} for a given {@link BeanFactory}.
* @param beanFactory the source bean factory
* @return the {@link BeanTypeRegistry} for the given bean factory
*/
static
BeanTypeRegistry
get
(
ListableBeanFactory
beanFactory
)
{
Assert
.
isInstanceOf
(
DefaultListableBeanFactory
.
class
,
beanFactory
);
DefaultListableBeanFactory
listableBeanFactory
=
(
DefaultListableBeanFactory
)
beanFactory
;
Assert
.
isTrue
(
listableBeanFactory
.
isAllowEagerClassLoading
(),
"Bean factory must allow eager class loading"
);
if
(!
listableBeanFactory
.
containsLocalBean
(
BEAN_NAME
))
{
BeanDefinition
bd
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
BeanTypeRegistry
.
class
,
()
->
new
BeanTypeRegistry
(
(
DefaultListableBeanFactory
)
beanFactory
))
.
getBeanDefinition
();
listableBeanFactory
.
registerBeanDefinition
(
BEAN_NAME
,
bd
);
}
return
listableBeanFactory
.
getBean
(
BEAN_NAME
,
BeanTypeRegistry
.
class
);
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java
View file @
1bd1ffdb
This diff is collapsed.
Click to expand it.
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