我想爲使用特定註釋註釋的私有方法創建一個切入點。然而,當註解位於像下面這樣的私有方法時,我的方面不會被觸發。註釋私有方法的AspectJ切入點
@Aspect
public class ServiceValidatorAspect {
@Pointcut("within(@com.example.ValidatorMethod *)")
public void methodsAnnotatedWithValidated() {
}
@AfterReturning(
pointcut = "methodsAnnotatedWithValidated()",
returning = "result")
public void throwExceptionIfErrorExists(JoinPoint joinPoint, Object result) {
...
}
服務接口
public interface UserService {
UserDto createUser(UserDto userDto);
}
服務實現
public class UserServiceImpl implements UserService {
public UserDto createUser(UserDto userDto) {
validateUser(userDto);
userDao.create(userDto);
}
@ValidatorMethod
private validateUser(UserDto userDto) {
// code here
}
但是如果我移動註釋到一個公共接口方法實現createUser
,我的方面被觸發。我應該如何定義我的切入點或配置我的方面以使我的原始用例起作用?
有沒有這方面的例子可以指向?謝謝! – 2018-02-08 01:02:34