[AI-8th] Add @Validated Support for Configuration Properties#1416
[AI-8th] Add @Validated Support for Configuration Properties#1416pmupkin wants to merge 3 commits intosofastack:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1416 +/- ##
============================================
+ Coverage 82.94% 83.20% +0.26%
- Complexity 2975 3014 +39
============================================
Files 340 341 +1
Lines 9833 9964 +131
Branches 1178 1188 +10
============================================
+ Hits 8156 8291 +135
+ Misses 1163 1161 -2
+ Partials 514 512 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds Bean Validation (JSR-303/Jakarta Validation) to key @ConfigurationProperties classes so invalid configuration values fail fast at startup with clearer error messages, aligning with issue #1405’s goal of improving configuration correctness and diagnostics.
Changes:
- Introduces
spring-boot-starter-validationto provide runtime validation support. - Adds
@Validatedand constraint annotations to multiple configuration properties classes (tracer/runtime/isle/health) and adds a custom class-level validator for RPC properties. - Adds/extends auto-configuration tests to assert startup fails with expected validation messages for invalid property values.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sofa-boot-project/sofaboot-dependencies/pom.xml | Manages spring-boot-starter-validation version for the build/BOM. |
| sofa-boot-project/sofa-boot-autoconfigure/pom.xml | Adds validation starter dependency to enable properties validation at runtime. |
| sofa-boot-project/sofa-boot-actuator-autoconfigure/pom.xml | Adds validation starter dependency for actuator autoconfigure validation. |
| sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/tracer/SofaTracerProperties.java | Adds @Validated and constraints for tracer-related properties. |
| sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeProperties.java | Adds @Validated, numeric constraints, and a cross-field pool-size validity check. |
| sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/isle/SofaModuleProperties.java | Adds @Validated and positivity constraints for parallel refresh settings. |
| sofa-boot-project/sofa-boot-actuator-autoconfigure/src/main/java/com/alipay/sofa/boot/actuator/autoconfigure/health/HealthProperties.java | Adds @Validated and positivity constraints for health timeouts. |
| sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcProperties.java | Enables validation and applies a class-level custom constraint. |
| sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/ValidSofaBootRpcProperties.java | New custom constraint annotation for RPC properties. |
| sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcPropertiesValidator.java | New validator implementing RPC cross-field/range/format validation with targeted messages. |
| sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/tracer/SofaTracerAutoConfigurationTests.java | Adds fail-fast test for invalid tracer sampling percentage. |
| sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeAutoConfigurationTests.java | Adds fail-fast test for invalid async executor sizing. |
| sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaRpcAutoConfigurationTests.java | Adds fail-fast test for invalid RPC port/weight settings. |
| sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/isle/SofaModuleAutoConfigurationTests.java | Adds fail-fast test for invalid parallel refresh factor. |
| sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/boot/actuator/autoconfigure/health/ReadinessAutoConfigurationTests.java | Adds fail-fast test for invalid health timeout. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@pmupkin Please change some of the Chinese descriptions to English. |
|
@pmupkin I noticed that some descriptions haven't been corrected yet, please change the description to English as soon as possible, thanks. |
| public class SofaBootRpcPropertiesValidator | ||
| implements | ||
| ConstraintValidator<ValidSofaBootRpcProperties, SofaBootRpcProperties> { | ||
|
|
||
| @Override | ||
| public boolean isValid(SofaBootRpcProperties value, ConstraintValidatorContext context) { | ||
| if (value == null) { | ||
| return true; | ||
| } | ||
| context.disableDefaultConstraintViolation(); | ||
| boolean valid = true; | ||
|
|
||
| valid = validatePort(context, valid, "boltPort", value.getBoltPort(), | ||
| "Bolt port must be between 1024 and 65535"); | ||
| valid = validatePort(context, valid, "h2cPort", value.getH2cPort(), | ||
| "H2C port must be between 1024 and 65535"); | ||
| valid = validatePort(context, valid, "restPort", value.getRestPort(), |
There was a problem hiding this comment.
Why does the verification of rpc need to be handled separately?
Related issue #1405
AI Agent: Codex-GPT-5.4 && Claude-Opus-4.6