I have a Jersey resource class which use field validation for header parameter.
@Controller
@RequiredArgsConstructor
public class Resource {
@Min(value = 0)
@HeaderParam("id")
private int id;
@HeaderParam("Authorization")
private String header;
@Authenticate
public void get() {
}
}
Then I create an Aspect which pointcut at @Authenticate annotation.
public class Aspect {
@Before("@annotation(Authenticate)")
public void doAuthenticate() {
}
}
The problem is that after creating the Aspect, the field validation for id no longer works (pass in -1 as id header will not violate the constraint).
I'm guessing the reason is that since Spring AOP is using CGLIB as the proxy, it doesn't fill fields when it creates the proxy, so a default value was passing to the validation, and then after getting out of Aspect, it's already out of the validation phase, hence the validation is not working.
So my questions are: 1. Am I understand correctly? 2. How can I make the field validation work?