Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 7eef3c2

Browse files
committed
Polish
See gh-1246
1 parent 1edf861 commit 7eef3c2

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

spring-aot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesNativeConfigurationProcessor.java

+17-16
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void process(ConfigurableListableBeanFactory beanFactory, NativeConfigura
6565

6666
private void processConfigurationProperties(NativeConfigurationRegistry registry, BeanDefinition beanDefinition) {
6767
Class<?> type = ClassUtils.getUserClass(beanDefinition.getResolvableType().toClass());
68-
new TypeProcessor(type).process(registry);
68+
TypeProcessor.process(type, registry);
6969
}
7070

7171
/**
@@ -82,31 +82,32 @@ private static class TypeProcessor {
8282

8383
private final BeanInfo beanInfo;
8484

85-
TypeProcessor(Class<?> type) {
86-
this(type, hasConstructorBinding(type));
87-
}
88-
8985
private TypeProcessor(Class<?> type, boolean constructorBinding) {
9086
this.type = type;
9187
this.constructorBinding = constructorBinding;
9288
this.beanInfo = getBeanInfo(type);
9389
}
9490

91+
public static void process(Class<?> type, NativeConfigurationRegistry registry) {
92+
if (type.getPackageName().startsWith("java.")) {
93+
return; // No reflection entries required for core types
94+
}
95+
new TypeProcessor(type, hasConstructorBinding(type)).process(registry);
96+
}
97+
9598
private static boolean hasConstructorBinding(AnnotatedElement element) {
9699
return MergedAnnotations.from(element).isPresent(ConstructorBinding.class);
97100
}
98101

99-
public void process(NativeConfigurationRegistry registry) {
102+
private void process(NativeConfigurationRegistry registry) {
100103
Builder reflection = registry.reflection().forType(this.type);
101-
if (!this.type.getPackageName().startsWith("java.")) {
102-
reflection.withFlags(Flag.allDeclaredMethods);
103-
Constructor<?> constructor = handleConstructor(reflection);
104-
if (this.constructorBinding && constructor != null) {
105-
handleValueObjectProperties(registry, constructor);
106-
}
107-
else if (this.beanInfo != null) {
108-
handleJavaBeanProperties(registry);
109-
}
104+
reflection.withFlags(Flag.allDeclaredMethods);
105+
Constructor<?> constructor = handleConstructor(reflection);
106+
if (this.constructorBinding && constructor != null) {
107+
handleValueObjectProperties(registry, constructor);
108+
}
109+
else if (this.beanInfo != null) {
110+
handleJavaBeanProperties(registry);
110111
}
111112
}
112113

@@ -139,7 +140,7 @@ private void handleJavaBeanProperties(NativeConfigurationRegistry registry) {
139140
ResolvableType propertyType = ResolvableType.forMethodReturnType(readMethod, this.type);
140141
Class<?> nestedType = getNestedType(propertyDescriptor.getName(), propertyType);
141142
if (nestedType != null) {
142-
new TypeProcessor(nestedType).process(registry);
143+
TypeProcessor.process(nestedType, registry);
143144
}
144145
}
145146
}

spring-aot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesNativeConfigurationProcessorTests.java

+19
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ void processJavaBeanConfigurationPropertiesWitArrayOfPojo() {
100100
assertThat(entries).hasSize(2);
101101
}
102102

103+
@Test
104+
void processJavaBeanConfigurationPropertiesWithListOfJavaType() {
105+
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
106+
beanFactory.registerBeanDefinition("beanA", BeanDefinitionBuilder
107+
.rootBeanDefinition(SamplePropertiesWithSimpleList.class).getBeanDefinition());
108+
NativeConfigurationRegistry registry = process(beanFactory);
109+
assertThat(registry.reflection().reflectionEntries()).singleElement()
110+
.satisfies(javaBeanBinding(SamplePropertiesWithSimpleList.class));
111+
}
112+
103113
@Test
104114
void processValueObjectConfigurationProperties() {
105115
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@@ -232,6 +242,15 @@ public List<Address> getAllAddresses() {
232242

233243
}
234244

245+
@ConfigurationProperties("test")
246+
static class SamplePropertiesWithSimpleList {
247+
248+
public List<String> getNames() {
249+
return Collections.emptyList();
250+
}
251+
252+
}
253+
235254
@ConfigurationProperties("test")
236255
static class SamplePropertiesWithArray {
237256

0 commit comments

Comments
 (0)