Spring AOP pointcut expression matching caller's context

240 Views Asked by At

I am using Spring AOP. I want my target method be matched only when invoked from a certain package. For example, let's assume my target method is com.domain.target.MyService.run(), and that it can be accessed from anywhere in my project. However, I want the pointcut to trigger only when the method is invoked from within a certain package, say com.domain.caller.*.

Is this something doable?

1

There are 1 best solutions below

2
Huy Nguyen On

Yes, it's able to advice with package.

We could also match any type within the package or a sub-package.

@Pointcut("within(com.domain.caller)")
@Pointcut("within(com.domain.caller.*)")

You can find more detail:

https://www.baeldung.com/spring-aop-pointcut-tutorial