I want to create a Pointcut for private methods that are annotated with a specific annotation. However my aspect is not triggered when the annotation is on a private method like below.
@Aspect
public class ServiceValidatorAspect {
@Pointcut("within(@com.example.ValidatorMethod *)")
public void methodsAnnotatedWithValidated() {
}
@AfterReturning(
pointcut = "methodsAnnotatedWithValidated()",
returning = "result")
public void throwExceptionIfErrorExists(JoinPoint joinPoint, Object result) {
...
}
Service Interface
public interface UserService {
UserDto createUser(UserDto userDto);
}
Service Implementation
public class UserServiceImpl implements UserService {
public UserDto createUser(UserDto userDto) {
validateUser(userDto);
userDao.create(userDto);
}
@ValidatorMethod
private validateUser(UserDto userDto) {
// code here
}
However if I move the annotation to a public interface method implementation createUser
, my aspect is triggered. How should I define my pointcut or configure my aspect to get my original use case working?