Fix binding detection of ConfigurationProperties contributed by @Bean

This commit makes sure that a ConfigurationProperties type contributed
by a `@Bean` factory method uses properties binding regardless of the
presence of a matching constructor.

`@Bean` method makes sure the user is in control and will be responsible
of creating the instance. As a result, binding of properties will not
happen there and therefore can only happen with regular JavaBean
accessors.

Closes gh-18184
This commit is contained in:
Stephane Nicoll
2019-09-09 11:48:08 +02:00
parent 0c0e2dd54b
commit 39fed4a9d9
3 changed files with 79 additions and 0 deletions

View File

@@ -51,6 +51,9 @@ class PropertyDescriptorResolver {
*/
Stream<PropertyDescriptor<?>> resolve(TypeElement type, ExecutableElement factoryMethod) {
TypeElementMembers members = new TypeElementMembers(this.environment, type);
if (factoryMethod != null) {
return resolveJavaBeanProperties(type, factoryMethod, members);
}
ExecutableElement constructor = resolveConstructor(type);
if (constructor != null) {
return resolveConstructorProperties(type, factoryMethod, members, constructor);