Skip to content

Commit 5770436

Browse files
committed
Immutable configuration properties not shown by Actuator
1 parent 9d0b7ed commit 5770436

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
5252
import org.springframework.boot.context.properties.ConfigurationProperties;
5353
import org.springframework.boot.context.properties.ConfigurationPropertiesBean;
54+
import org.springframework.boot.context.properties.ConstructorBinding;
5455
import org.springframework.context.ApplicationContext;
5556
import org.springframework.context.ApplicationContextAware;
5657
import org.springframework.util.ClassUtils;
@@ -69,6 +70,7 @@
6970
* @author Christian Dupuis
7071
* @author Dave Syer
7172
* @author Stephane Nicoll
73+
* @author Leo Li
7274
* @since 2.0.0
7375
*/
7476
@Endpoint(id = "configprops")
@@ -312,6 +314,13 @@ public List<BeanPropertyWriter> changeProperties(SerializationConfig config, Bea
312314
}
313315

314316
private boolean isReadable(BeanDescription beanDesc, BeanPropertyWriter writer) {
317+
// if the class has the @ConstructorBinding annotation or
318+
// one constructor of this class has the @ConstructorBinding annotation,
319+
// we can ignore the setter method.
320+
if (beanDesc.getClassAnnotations().has(ConstructorBinding.class)
321+
|| isConstructorsContainConstructorBinding(beanDesc)) {
322+
return true;
323+
}
315324
Class<?> parentType = beanDesc.getType().getRawClass();
316325
Class<?> type = writer.getType().getRawClass();
317326
AnnotatedMethod setter = findSetter(beanDesc, writer);
@@ -325,6 +334,11 @@ private boolean isReadable(BeanDescription beanDesc, BeanPropertyWriter writer)
325334
|| Map.class.isAssignableFrom(type) || Collection.class.isAssignableFrom(type);
326335
}
327336

337+
private boolean isConstructorsContainConstructorBinding(BeanDescription beanDesc) {
338+
return beanDesc.getConstructors().stream()
339+
.anyMatch((annotatedConstructor) -> annotatedConstructor.hasAnnotation(ConstructorBinding.class));
340+
}
341+
328342
private AnnotatedMethod findSetter(BeanDescription beanDesc, BeanPropertyWriter writer) {
329343
String name = "set" + determineAccessorSuffix(writer.getName());
330344
Class<?> type = writer.getType().getRawClass();

0 commit comments

Comments
 (0)