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
2c4a1f1c
Commit
2c4a1f1c
authored
Dec 04, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display @Validated constructor bound properties in configprops endpoint
Fixes gh-19219
parent
05d460a9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
1 deletion
+81
-1
pom.xml
spring-boot-project/spring-boot-actuator/pom.xml
+5
-0
ConfigurationPropertiesReportEndpoint.java
...ext/properties/ConfigurationPropertiesReportEndpoint.java
+2
-1
ConfigurationPropertiesReportEndpointProxyTests.java
...ties/ConfigurationPropertiesReportEndpointProxyTests.java
+30
-0
ValidatedConstructorBindingProperties.java
...ext/properties/ValidatedConstructorBindingProperties.java
+44
-0
No files found.
spring-boot-project/spring-boot-actuator/pom.xml
View file @
2c4a1f1c
...
...
@@ -345,6 +345,11 @@
<artifactId>
log4j-to-slf4j
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.tomcat.embed
</groupId>
<artifactId>
tomcat-embed-el
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.glassfish.jersey.media
</groupId>
<artifactId>
jersey-media-json-jackson
</artifactId>
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java
View file @
2c4a1f1c
...
...
@@ -310,7 +310,8 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
public
List
<
BeanPropertyWriter
>
changeProperties
(
SerializationConfig
config
,
BeanDescription
beanDesc
,
List
<
BeanPropertyWriter
>
beanProperties
)
{
List
<
BeanPropertyWriter
>
result
=
new
ArrayList
<>();
Constructor
<?>
bindConstructor
=
findBindConstructor
(
beanDesc
.
getType
().
getRawClass
());
Class
<?>
beanClass
=
beanDesc
.
getType
().
getRawClass
();
Constructor
<?>
bindConstructor
=
findBindConstructor
(
ClassUtils
.
getUserClass
(
beanClass
));
for
(
BeanPropertyWriter
writer
:
beanProperties
)
{
if
(
isCandidate
(
beanDesc
,
writer
,
bindConstructor
))
{
result
.
add
(
writer
);
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointProxyTests.java
View file @
2c4a1f1c
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
actuate
.
context
.
properties
;
import
java.util.Map
;
import
javax.sql.DataSource
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -27,6 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
;
...
...
@@ -35,6 +38,7 @@ import org.springframework.transaction.PlatformTransactionManager;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.validation.beanvalidation.MethodValidationPostProcessor
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -44,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Madhura Bhave
*/
class
ConfigurationPropertiesReportEndpointProxyTests
{
...
...
@@ -60,6 +65,19 @@ class ConfigurationPropertiesReportEndpointProxyTests {
});
}
@Test
void
proxiedConstructorBoundPropertiesShouldBeAvailableInReport
()
{
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withUserConfiguration
(
ValidatedConfiguration
.
class
).
withPropertyValues
(
"validated.name=baz"
);
contextRunner
.
run
((
context
)
->
{
ApplicationConfigurationProperties
applicationProperties
=
context
.
getBean
(
ConfigurationPropertiesReportEndpoint
.
class
).
configurationProperties
();
Map
<
String
,
Object
>
properties
=
applicationProperties
.
getContexts
().
get
(
context
.
getId
()).
getBeans
()
.
values
().
stream
().
map
(
ConfigurationPropertiesBeanDescriptor:
:
getProperties
).
findFirst
().
get
();
assertThat
(
properties
.
get
(
"name"
)).
isEqualTo
(
"baz"
);
});
}
@Configuration
(
proxyBeanMethods
=
false
)
@EnableTransactionManagement
(
proxyTargetClass
=
false
)
@EnableConfigurationProperties
...
...
@@ -75,6 +93,11 @@ class ConfigurationPropertiesReportEndpointProxyTests {
return
new
DataSourceTransactionManager
(
dataSource
);
}
@Bean
MethodValidationPostProcessor
testPostProcessor
()
{
return
new
MethodValidationPostProcessor
();
}
@Bean
DataSource
dataSource
()
{
return
new
EmbeddedDatabaseBuilder
().
setType
(
EmbeddedDatabaseType
.
HSQL
).
build
();
...
...
@@ -103,4 +126,11 @@ class ConfigurationPropertiesReportEndpointProxyTests {
}
@Configuration
(
proxyBeanMethods
=
false
)
@EnableConfigurationProperties
(
ValidatedConstructorBindingProperties
.
class
)
@Import
(
Config
.
class
)
static
class
ValidatedConfiguration
{
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ValidatedConstructorBindingProperties.java
0 → 100644
View file @
2c4a1f1c
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
actuate
.
context
.
properties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConstructorBinding
;
import
org.springframework.validation.annotation.Validated
;
/**
* Used for testing the {@link ConfigurationPropertiesReportEndpoint} endpoint with
* validated {@link ConfigurationProperties @ConfigurationProperties}.
*
* @author Madhura Bhave
*/
@Validated
@ConstructorBinding
@ConfigurationProperties
(
prefix
=
"validated"
)
public
class
ValidatedConstructorBindingProperties
{
private
final
String
name
;
ValidatedConstructorBindingProperties
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
this
.
name
;
}
}
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