带注释的PRIVATE方法的AspectJ切入点 [英] AspectJ pointcut for annotated PRIVATE methods
本文介绍了带注释的PRIVATE方法的AspectJ切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为带有特定注释的私有方法创建切入点.但是,当注释在如下所示的私有方法上时,不会触发我的方面.
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) {
...
}
服务界面
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
,则会触发我的方面.我应该如何定义切入点或配置方面以使原始用例正常工作?
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?
推荐答案
查看全文