Skip to content

Configure @ConfigurationProperties binding for programmatically regis…#50488

Closed
ujjawal-tyagi wants to merge 1 commit into
spring-projects:mainfrom
ujjawal-tyagi:fix/bean-registrar-configuration-properties
Closed

Configure @ConfigurationProperties binding for programmatically regis…#50488
ujjawal-tyagi wants to merge 1 commit into
spring-projects:mainfrom
ujjawal-tyagi:fix/bean-registrar-configuration-properties

Conversation

@ujjawal-tyagi
Copy link
Copy Markdown

…tered beans

When beans annotated with @ConfigurationProperties are registered programmatically (for example, via BeanRegistrar or registerBeanDefinition) without going through ConfigurationPropertiesBeanRegistrar, the required BindMethodAttribute is not stamped on the BeanDefinition. This causes ConfigurationPropertiesBindingPostProcessor to fall back to setter-based binding, which fails for immutable types such as Kotlin data classes.

Introduce ConfigurationPropertiesBeanDefinitionPostProcessor, a BeanDefinitionRegistryPostProcessor with HIGHEST_PRECEDENCE that runs before bean instantiation. It iterates all registered bean definitions, deduces the correct BindMethod for any @ConfigurationProperties type that lacks the attribute, and stamps BindMethodAttribute accordingly. For VALUE_OBJECT types it also installs a constructor-binding instanceSupplier via ConstructorBound. Additionally, it deduplicates scan-registered definitions when a custom registration exists for the same type.

Closes gh-xxxx

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 23, 2026
…tered beans

When beans annotated with @ConfigurationProperties are registered
programmatically (for example, via BeanRegistrar or registerBeanDefinition)
without going through ConfigurationPropertiesBeanRegistrar, the required
BindMethodAttribute is not stamped on the BeanDefinition. This causes
ConfigurationPropertiesBindingPostProcessor to fall back to setter-based
binding, which fails for immutable types such as Kotlin data classes.

Introduce ConfigurationPropertiesBeanDefinitionPostProcessor, a
BeanDefinitionRegistryPostProcessor with HIGHEST_PRECEDENCE that runs
before bean instantiation. It iterates all registered bean definitions and,
for any @ConfigurationProperties type that lacks BindMethodAttribute,
delegates to the new ConfigurationPropertiesBeanRegistrar.enrichBeanDefinition
static method. This keeps the enrichment logic in a single place: the same
deduceBindMethod call and instanceSupplier setup used by the existing
scan and @enable paths.

Closes gh-xxxx

Signed-off-by: ujjawal tyagi <ujjawaltyagi@gmail.com>
@ujjawal-tyagi ujjawal-tyagi force-pushed the fix/bean-registrar-configuration-properties branch from 2d20816 to 3d56d76 Compare May 24, 2026 04:35
@snicoll
Copy link
Copy Markdown
Member

snicoll commented May 24, 2026

Thanks for trying to help but working on an issue that is waiting-for-triage is not a good idea. The issue has been triaged and rejected, see the conversation in #50486

@snicoll snicoll closed this May 24, 2026
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants