I am using Spring's AspectJ with CGLIB proxying. I have an aspect defined as below, where I want it to advise public methods on concrete classes that are annotated with the annotation 'ValidatorMethod':
@Aspect
public class ServiceValidatorAspect {
@Pointcut("within(@com.example.ValidatorMethod *)")
public void methodsAnnotatedWithValidated() {
}
@AfterReturning(
pointcut = "methodsAnnotatedWithValidated()",
returning = "result")
public void throwExceptionIfErrorExists(JoinPoint joinPoint, Object result) {
...
}
Example Service Interface
public interface UserService {
UserDto createUser(UserDto userDto);
}
Example Service Implementation
public class UserServiceImpl implements UserService {
public UserDto createUser(UserDto userDto) {
validateUser(userDto);
userDao.create(userDto);
}
@ValidatorMethod
public void validateUser(UserDto userDto) {
// code here
}
}
AOP spring config:
<aop:aspectj-autoproxy proxy-target-class="true"/>
As I understand it, setting proxy-target-class to "true" will result in public methods in concrete classes being proxied, not just interface methods. However my aspect is not triggered. Any ideas as to what is wrong? I know my UserServiceImpl class is being proxied correctly by CGLIB as I can verify that in the callstack in the debugger.