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
c11abf48
Commit
c11abf48
authored
Jun 06, 2020
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish 'Allow beans without public constructors to load'
See gh-20929
parent
d8d8f9cf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
4 deletions
+15
-4
BeanDefinitionLoader.java
...n/java/org/springframework/boot/BeanDefinitionLoader.java
+14
-3
BeanDefinitionLoaderTests.java
...a/org/springframework/boot/BeanDefinitionLoaderTests.java
+1
-0
MyNamedComponent.java
...g/springframework/boot/sampleconfig/MyNamedComponent.java
+0
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java
View file @
c11abf48
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
;
package
org
.
springframework
.
boot
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.lang.reflect.Constructor
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -41,6 +42,7 @@ import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilte
...
@@ -41,6 +42,7 @@ import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilte
import
org.springframework.core.type.filter.TypeFilter
;
import
org.springframework.core.type.filter.TypeFilter
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
...
@@ -151,7 +153,7 @@ class BeanDefinitionLoader {
...
@@ -151,7 +153,7 @@ class BeanDefinitionLoader {
GroovyBeanDefinitionSource
loader
=
BeanUtils
.
instantiateClass
(
source
,
GroovyBeanDefinitionSource
.
class
);
GroovyBeanDefinitionSource
loader
=
BeanUtils
.
instantiateClass
(
source
,
GroovyBeanDefinitionSource
.
class
);
load
(
loader
);
load
(
loader
);
}
}
if
(
is
Component
(
source
))
{
if
(
is
Eligible
(
source
))
{
this
.
annotatedReader
.
register
(
source
);
this
.
annotatedReader
.
register
(
source
);
return
1
;
return
1
;
}
}
...
@@ -277,8 +279,17 @@ class BeanDefinitionLoader {
...
@@ -277,8 +279,17 @@ class BeanDefinitionLoader {
* @return true if the given bean type is eligible for registration, i.e. not a groovy
* @return true if the given bean type is eligible for registration, i.e. not a groovy
* closure nor an anonymous class
* closure nor an anonymous class
*/
*/
private
boolean
isComponent
(
Class
<?>
type
)
{
private
boolean
isEligible
(
Class
<?>
type
)
{
return
!
type
.
getName
().
matches
(
".*\\$_.*closure.*"
)
&&
!
type
.
isAnonymousClass
();
return
!(
type
.
isAnonymousClass
()
||
isGroovyClosure
(
type
)
||
hasNoConstructors
(
type
));
}
private
boolean
isGroovyClosure
(
Class
<?>
type
)
{
return
type
.
getName
().
matches
(
".*\\$_.*closure.*"
);
}
private
boolean
hasNoConstructors
(
Class
<?>
type
)
{
Constructor
<?>[]
constructors
=
type
.
getDeclaredConstructors
();
return
ObjectUtils
.
isEmpty
(
constructors
);
}
}
/**
/**
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BeanDefinitionLoaderTests.java
View file @
c11abf48
...
@@ -58,6 +58,7 @@ class BeanDefinitionLoaderTests {
...
@@ -58,6 +58,7 @@ class BeanDefinitionLoaderTests {
@Test
@Test
void
anonymousClassNotLoaded
()
{
void
anonymousClassNotLoaded
()
{
MyComponent
myComponent
=
new
MyComponent
()
{
MyComponent
myComponent
=
new
MyComponent
()
{
};
};
BeanDefinitionLoader
loader
=
new
BeanDefinitionLoader
(
this
.
registry
,
myComponent
.
getClass
());
BeanDefinitionLoader
loader
=
new
BeanDefinitionLoader
(
this
.
registry
,
myComponent
.
getClass
());
assertThat
(
loader
.
load
()).
isEqualTo
(
0
);
assertThat
(
loader
.
load
()).
isEqualTo
(
0
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/sampleconfig/MyNamedComponent.java
View file @
c11abf48
...
@@ -22,7 +22,6 @@ import javax.inject.Named;
...
@@ -22,7 +22,6 @@ import javax.inject.Named;
public
class
MyNamedComponent
{
public
class
MyNamedComponent
{
MyNamedComponent
()
{
MyNamedComponent
()
{
}
}
}
}
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