Код: Выделить всё
@Target({ElementType.METHOD,ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = HeaderValidator.class)
public @interface ValidateClientId{
public String message() default "Invalid client ID";
}
Код: Выделить всё
public class HeaderValidator implements ConstraintValidator{
@Override
public void initialize(ValidateClientId clientId) {
System.out.println("inside initialize -->" +clientId);
}
@Override
public boolean isValid(String clientId, ConstraintValidatorContext constraintValidatorContext) {
System.out.println("inside isValid method -->" +clientId);
return clientId.length()
Я добавил эту аннотацию на этот метод вызов в сервисный уровень, но это не работает. < /p>
@Override
public ResponseEntity processEmployeeData(String version, @ValidateClientId String clientId) {
}
Код: Выделить всё
@Aspect
@Component
public class AspectValidator {
private final EmployeeService employeeService;
public AspectValidator(EmployeeService employeeService) {
this.employeeService = employeeService;
}
@Before("@annotation(com.api.validation.ValidateClientId)")
public void beforeAnnotation(JoinPoint joinPoint){
System.out.println("inside beforeAnnotation -->");
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
ValidateClientId annotation = signature.getMethod().getAnnotation(ValidateClientId.class);
....
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... ot-working