custom annotation
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation {
}
custom annotation handler
@Aspect
public class TestAspectHandler {
@Around("execution(@com.test.project.annotaion.CustomAnnotation * *(..)) && @annotation(customAnnotation)")
public Object testAnnotation(ProceedingJoinPoint joinPoint, CustomAnnotation customAnnotation) throws Throwable {
System.out.println("TEST");
return result;
}
}
super class
public class AbstractDAO {
@CustomAnnotation
protected int selectOne(Object params){
// .... something
}
}
sub class
public class SubDAO extends AbstractDAO {
public int selectSub(Object params) {
return selectOne(params);
}
}
subclass SubDAO
call SuperClass method selectOne
but in TestAspectHandler.class
doesn't call testAnnotation(...)
when i move @CustomAnnotation
to subclass selectSub(..)
method AspectHandler can get joinPoint
how to work with Custom annotation in super class protected method?
added
change TestAspectHandler.testAnnotation(...) method
@Around("execution(* *(..)) && @annotation(customAnnotation)")
public Object testAnnotation(ProceedingJoinPoint joinPoint, CustomAnnotation customAnnotation) throws Throwable {
System.out.println("TEST");
return result;
}
but still doesn't work
so i chnage my SubDAO
like under code
public class SubDAO extends AbstractDAO {
@Autowired
private AbstractDAO abstractDAO;
public int selectSub(Object params) {
return abstractDAO.selectOne(params);
}
}
this is not the perfect solution but it work
- case 1 : call Super class method from subclass method doesn't work
- case 2 : make Super class instance and call from instance work