Open
Description
demo project link: https://github.com/mingchiuli/demo
public class AnnoValidator implements ConstraintValidator<Anno, Pojo> {
@Resource
private TestComponent testComponent;
@Override
public boolean isValid(Pojo value, ConstraintValidatorContext context) {
testComponent.call();
return true;
}
}
In Spring boot 3.3.6, I found if I injected a component in a implement Class of ConstraintValidator in JVM mode, it worked normal:
(console output:)
123
test
But It would generated a NullPointerExeception in GraalVM's native-image :
2024-12-12T12:46:54.279+08:00 ERROR 36733 --- [demo] [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: jakarta.validation.ValidationException: HV000028: Unexpected exception during isValid call.] with root cause
java.lang.NullPointerException: null
at com.example.demo.pkg.AnnoValidator.isValid(AnnoValidator.java:14) ~[demo:na]
at com.example.demo.pkg.AnnoValidator.isValid(AnnoValidator.java:7) ~[demo:na]
It seems the TestComponent
can't be injected in native-image mode