Skip to content

Config property validation doesn't work for bindings that are only configured through default configs #2974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Nephery opened this issue Jul 18, 2024 · 2 comments

Comments

@Nephery
Copy link

Nephery commented Jul 18, 2024

Describe the issue

If a binder has @Validated set on its AbstractExtendedBindingProperties implementation, then annotation-driven validation works as expected when bindings have at least one configs set through a binding-specific config option (i.e. spring.cloud.stream.<binder-type>.bindings.<binding-name>.(consumer|producer).<property-name>).

e.g.: Suppose batch-max-size=0 in the following config is invalid (@Min(1)):

spring.cloud.stream.solace.bindings.my-input-binding.consumer.transacted=true
spring.cloud.stream.solace.default.consumer.batch-max-size=0

Then validation would successfully fail here, because there's at least one config explicitly referring to the binding, my-input-binding:

***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target com.solace.spring.cloud.stream.binder.properties.SolaceExtendedBindingProperties failed:

    Property: spring.cloud.stream.solace.bindings.my-input-binding.consumer.batchMaxSize
    Value: "0"
    Reason: must be greater than or equal to 1

But if the binding is configured only through default configs, then config validation doesn't work:

spring.cloud.stream.solace.default.consumer.transacted=true
spring.cloud.stream.solace.default.consumer.batch-max-size=0

In this config, batch-max-size=0 isn't validated because there was no explicit configuration referring to my-input-binding.

To Reproduce
Steps to reproduce the behavior:

  1. Add @Validated to a binder's AbstractExtendedBindingProperties, whose consumer or producer bindings has a constraint annotation like @Min().
  2. Configure the SCSt app's application.yml or application.properties to fail the constraint through a default binding config.
  3. Notice that no validation error is thrown.

Version of the framework
Spring Boot: 3.3.1
Spring Cloud: 2023.0.2

Expected behavior
Expected validation to work when bindings are only configured through default values.

Additional context
Please tag as [solace].

@olegz olegz added the SOLACE label Sep 26, 2024
@olegz
Copy link
Contributor

olegz commented Oct 1, 2024

This is a bit tricky as it involves hierarchy of standard @ConfiguirationProperties and their extensions. The same problem is in Rabbit and Kafka, but I am close to figuring it out

@olegz olegz added the bug label Oct 2, 2024
@olegz olegz added this to the 4.2.0-M2 milestone Oct 2, 2024
@olegz
Copy link
Contributor

olegz commented Oct 2, 2024

Back-porting it to 4.1.x as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants