We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In a same Springboot project, we have a record configuration property:
@ConfigurationProperties(prefix = "myapp") @Validated public record MyProperties(@NotBlank String property) {}
If we want to enhance method level validation by creating a bean:
@Bean public MethodValidationPostProcessor methodValidationPostProcessor() { return new MethodValidationPostProcessor(); }
Then when the application starts we have an exception java.lang.IllegalArgumentException: Cannot subclass final class com.example.demo.MyProperties.
java.lang.IllegalArgumentException: Cannot subclass final class com.example.demo.MyProperties
It seems that Spring tries to make a cglib proxy for the record, which obviously won't work.
You will find a minimal setup to reproduce in this repo.
We found a workaround by explicitly removing the record:
public MethodValidationPostProcessor methodValidationPostProcessor() { return new MethodValidationPostProcessor() { @Override public boolean isEligible(Object bean, String beanName) { if (bean.getClass().isRecord()) { return false; } return super.isEligible(bean, beanName); } }; }
The text was updated successfully, but these errors were encountered:
This is the expected behavior I am afraid see https://docs.spring.io/spring-framework/reference/core/validation/beanvalidation.html#validation-beanvalidation-spring-method and some more discussion in spring-projects/spring-framework#27868
Sorry, something went wrong.
No branches or pull requests
What happens
In a same Springboot project, we have a record configuration property:
If we want to enhance method level validation by creating a bean:
Then when the application starts we have an exception
java.lang.IllegalArgumentException: Cannot subclass final class com.example.demo.MyProperties
.It seems that Spring tries to make a cglib proxy for the record, which obviously won't work.
Minimal setup to reproduce
You will find a minimal setup to reproduce in this repo.
Work around
We found a workaround by explicitly removing the record:
The text was updated successfully, but these errors were encountered: