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
89aefa6c
Commit
89aefa6c
authored
Aug 02, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable binding for scanned configuration properties
Closes gh-16822
parent
2784fc15
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
4 deletions
+37
-4
ConfigurationPropertiesScan.java
.../boot/context/properties/ConfigurationPropertiesScan.java
+1
-1
ConfigurationPropertiesScanRegistrarTests.java
...properties/ConfigurationPropertiesScanRegistrarTests.java
+3
-1
ConfigurationPropertiesScanTests.java
.../context/properties/ConfigurationPropertiesScanTests.java
+13
-2
BScanConfiguration.java
...t/context/properties/scan/valid/b/BScanConfiguration.java
+20
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesScan.java
View file @
89aefa6c
...
...
@@ -37,7 +37,7 @@ import org.springframework.core.annotation.AliasFor;
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Import
(
ConfigurationPropertiesScanRegistrar
.
class
)
@Import
(
{
ConfigurationPropertiesScanRegistrar
.
class
,
ConfigurationPropertiesBindingPostProcessorRegistrar
.
class
}
)
public
@interface
ConfigurationPropertiesScan
{
/**
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrarTests.java
View file @
89aefa6c
...
...
@@ -92,7 +92,9 @@ class ConfigurationPropertiesScanRegistrarTests {
BeanDefinition
bSecondDefinition
=
beanFactory
.
getBeanDefinition
(
"b.second-org.springframework.boot.context.properties.scan.valid.b.BScanConfiguration$BSecondProperties"
);
assertThat
(
aDefinition
).
isExactlyInstanceOf
(
GenericBeanDefinition
.
class
);
assertThat
(
bFirstDefinition
).
isExactlyInstanceOf
(
GenericBeanDefinition
.
class
);
// Constructor injection
assertThat
(
bFirstDefinition
).
isExactlyInstanceOf
(
ConfigurationPropertiesBeanDefinition
.
class
);
// Post-processing injection
assertThat
(
bSecondDefinition
).
isExactlyInstanceOf
(
GenericBeanDefinition
.
class
);
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java
View file @
89aefa6c
...
...
@@ -27,12 +27,14 @@ import org.springframework.boot.context.TypeExcludeFilter;
import
org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration
;
import
org.springframework.boot.context.properties.scan.valid.b.BScanConfiguration.BFirstProperties
;
import
org.springframework.boot.context.properties.scan.valid.b.BScanConfiguration.BProperties
;
import
org.springframework.boot.context.properties.scan.valid.b.BScanConfiguration.BSecondProperties
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.type.classreading.MetadataReader
;
import
org.springframework.core.type.classreading.MetadataReaderFactory
;
import
org.springframework.core.type.filter.AssignableTypeFilter
;
import
org.springframework.test.context.support.TestPropertySourceUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
...
@@ -44,6 +46,7 @@ import static org.mockito.Mockito.mock;
*
* @author Madhura Bhave
* @author Johnny Lim
* @author Stephane Nicoll
*/
class
ConfigurationPropertiesScanTests
{
...
...
@@ -115,8 +118,16 @@ class ConfigurationPropertiesScanTests {
"b.first-org.springframework.boot.context.properties.scan.valid.b.BScanConfiguration$BFirstProperties"
);
}
private
void
load
(
Class
<?>...
classes
)
{
this
.
context
.
register
(
classes
);
@Test
void
scanShouldBindConfigurationProperties
()
{
load
(
TestAnotherPackageConfiguration
.
class
,
"b.first.name=constructor"
,
"b.second.number=42"
);
assertThat
(
this
.
context
.
getBean
(
BFirstProperties
.
class
).
getName
()).
isEqualTo
(
"constructor"
);
assertThat
(
this
.
context
.
getBean
(
BSecondProperties
.
class
).
getNumber
()).
isEqualTo
(
42
);
}
private
void
load
(
Class
<?>
configuration
,
String
...
inlinedProperties
)
{
this
.
context
.
register
(
configuration
);
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
inlinedProperties
);
this
.
context
.
refresh
();
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/scan/valid/b/BScanConfiguration.java
View file @
89aefa6c
...
...
@@ -30,11 +30,31 @@ public class BScanConfiguration {
@ConfigurationProperties
(
prefix
=
"b.first"
)
public
static
class
BFirstProperties
implements
BProperties
{
private
final
String
name
;
public
BFirstProperties
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
this
.
name
;
}
}
@ConfigurationProperties
(
prefix
=
"b.second"
)
public
static
class
BSecondProperties
implements
BProperties
{
private
int
number
;
public
int
getNumber
()
{
return
this
.
number
;
}
public
void
setNumber
(
int
number
)
{
this
.
number
=
number
;
}
}
}
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