In my Spring Boot application I have working a pointcut against an interface that successfully works using "execution". I tried converting it to "within" as an exercise following a tutorial and it is not working and I can't figure out why.
Here is Service Interface:
package com.test.services;
import com.test.model.MyObject;
public interface MyService {
MyObject get(Long id);
}
Here is Aspect that works:
package com.test.aop;
import org.aspectJ.lang.annoation.Aspect;
import org.aspectJ.lang.annoation.Before;
import org.aspectJ.lang.annoation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class MyAspect {
@Pointcut("execution(* com.test.services.MyService.*(..))")
public void anyMyServiceMethod() {}
@Before("anyMyServiceMethod()")
public void beforeAnyServiceMethod() {
System.out.println("HERE!");
}
}
I changed it to this and it doesn't work:
package com.test.aop;
import org.aspectJ.lang.annoation.Aspect;
import org.aspectJ.lang.annoation.Before;
import org.aspectJ.lang.annoation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class MyAspect {
@Pointcut("within(com.test.services.*)")
public void anyMyServiceMethod() {}
@Before("anyMyServiceMethod()")
public void beforeAnyServiceMethod() {
System.out.println("HERE!");
}
}
From what I read I thought the pointcut above using "within" should match any method in the package com.test.services but it is not. Am I missing something?