mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish "Fix NPE in configprops endpoint"
See gh-30068
This commit is contained in:
parent
a1fe05f40b
commit
35154a96f3
@ -121,7 +121,7 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
|
|||||||
|
|
||||||
@ReadOperation
|
@ReadOperation
|
||||||
public ApplicationConfigurationProperties configurationProperties() {
|
public ApplicationConfigurationProperties configurationProperties() {
|
||||||
return extract(this.context, (bean) -> bean != null);
|
return extract(this.context, (bean) -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadOperation
|
@ReadOperation
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -143,14 +143,12 @@ public final class ConfigurationPropertiesBean {
|
|||||||
return getAll((ConfigurableApplicationContext) applicationContext);
|
return getAll((ConfigurableApplicationContext) applicationContext);
|
||||||
}
|
}
|
||||||
Map<String, ConfigurationPropertiesBean> propertiesBeans = new LinkedHashMap<>();
|
Map<String, ConfigurationPropertiesBean> propertiesBeans = new LinkedHashMap<>();
|
||||||
applicationContext.getBeansWithAnnotation(ConfigurationProperties.class)
|
applicationContext.getBeansWithAnnotation(ConfigurationProperties.class).forEach((beanName, bean) -> {
|
||||||
.forEach((beanName, bean) -> {
|
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
|
||||||
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
|
if (propertiesBean != null) {
|
||||||
if (propertiesBean == null) { //ignore for null
|
propertiesBeans.put(beanName, propertiesBean);
|
||||||
return;
|
}
|
||||||
}
|
});
|
||||||
propertiesBeans.put(beanName,propertiesBean);
|
|
||||||
});
|
|
||||||
return propertiesBeans;
|
return propertiesBeans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,10 +162,9 @@ public final class ConfigurationPropertiesBean {
|
|||||||
try {
|
try {
|
||||||
Object bean = beanFactory.getBean(beanName);
|
Object bean = beanFactory.getBean(beanName);
|
||||||
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
|
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
|
||||||
if (propertiesBean == null) { //ignore for null
|
if (propertiesBean != null) {
|
||||||
continue;
|
propertiesBeans.put(beanName, propertiesBean);
|
||||||
}
|
}
|
||||||
propertiesBeans.put(beanName, propertiesBean);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,15 @@ class ConfigurationPropertiesBeanTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getAllDoesNotFindABeanDeclaredInAStaticBeanMethodOnAConfigurationAndConfigurationPropertiesAnnotatedClass() {
|
||||||
|
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
StaticBeanMethodConfiguration.class)) {
|
||||||
|
Map<String, ConfigurationPropertiesBean> all = ConfigurationPropertiesBean.getAll(context);
|
||||||
|
assertThat(all).containsOnlyKeys("configurationPropertiesBeanTests.StaticBeanMethodConfiguration");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getAllWhenHasBadBeanDoesNotFail() {
|
void getAllWhenHasBadBeanDoesNotFail() {
|
||||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
@ -521,4 +530,15 @@ class ConfigurationPropertiesBeanTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConfigurationProperties
|
||||||
|
static class StaticBeanMethodConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
static String stringBean() {
|
||||||
|
return "example";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user