Quick revision
The short answer
All public methods in classes in com.acme.service and its sub-packages are matched by execution(public * com.acme.service..*.*(..)). Methods annotated with @Audited are matched by @annotation(com.acme.Audited), and every method of beans whose name ends with Client is matched by bean(*Client), a designator that only Spring AOP supports. Expressions can be combined with &&, || and !, and naming them on @Pointcut methods lets us reuse them across advice.
What to remember
In this answer, we wrote three pointcuts. execution(public * com.acme.service..*.*(..)) matches public methods in the package and all sub-packages, where the double dot is the part that brings in sub-packages. @annotation(com.acme.Audited) matches methods carrying a runtime-retained annotation. bean(*Client) matches every method of beans whose Spring bean name ends with Client, and works only in Spring AOP. We combined them with &&, || and ! and named them with @Pointcut methods for reuse.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
All public methods in classes in com.acme.service and its sub-packages are matched by execution(public * com.acme.service..*.*(..)). Methods annotated with @Audited are matched by @annotation(com.acme.Audited), and every method of beans whose name ends with Client is matched by bean(*Client), a designator that only Spring AOP supports. Expressions can be combined with &&, || and !, and naming them on @Pointcut methods lets us reuse them across advice.
Why this question is asked
Pointcut expressions are short, but a single misplaced dot or star can make an aspect match nothing, or match every bean in the application. Interviewers ask candidates to write a few of them because it quickly shows whether we understand the pieces of the syntax rather than copying examples. In this answer, we will recap what a pointcut is, take apart each of the three expressions symbol by symbol, check what each one matches and does not match, and then combine and name them in a small aspect.
1A Quick Recap of Pointcuts
In Spring AOP, a pointcut is an expression that selects the method executions an advice should run at. Spring borrows the expression language from AspectJ. Each expression starts with a designator, a keyword such as execution, @annotation or bean, which says what kind of thing we are matching on, followed by a pattern in parentheses. Spring evaluates the expression against each bean's methods when it decides whether to create a proxy, and again for each method to decide which advice applies.
2Expression 1: Public Methods in a Package and Its Sub-Packages
The execution designator matches on the method signature. Its pattern has the shape modifiers, return type, declaring type and method name, and parameters, with an optional throws clause at the end.
Notice the two dots after service. A single dot, com.acme.service.*.*(..), would match only types directly in com.acme.service, while .. means this package and any depth below it. The modifier public can be left out, and in practice Spring AOP with proxies only intercepts methods the proxy can reach, but stating public makes the intent clear and matters if the aspect is ever woven with AspectJ.
3Expression 2: Methods Annotated With @Audited
The @annotation designator matches a method execution when the method itself carries the given annotation. The annotation must have runtime retention, otherwise it is not visible when Spring checks.
The annotation's type name must be fully qualified unless the aspect is in the same package. There is also a binding form, @annotation(audited) with a parameter Audited audited in the advice method, which gives the advice access to the annotation's attributes, for example to record audited.value().
4Expression 3: All Methods of Beans Named Like *Client
The bean designator matches on the Spring bean name, not the Java type. It accepts a name pattern with * as a wildcard.
| Expression | Matches on | Notes |
|---|---|---|
execution(public * com.acme.service..*.*(..)) | method signature and declaring type | the .. means sub-packages too |
@annotation(com.acme.Audited) | annotation on the method | needs RUNTIME retention |
bean(*Client) | Spring bean name | Spring AOP only, not AspectJ |
Notice that the bean name is what counts: a class called PaymentGatewayAdapter registered as paymentClient matches, while a class called HttpClient registered as httpClientFactory does not. bean() exists only in Spring AOP, because AspectJ knows nothing about Spring bean names. If the aspect is ever woven with the AspectJ compiler or load-time weaver, an expression using bean() will fail, so it is best kept to aspects that will always be proxy-based.
5Combining and Naming Pointcuts
Expressions can be combined with && (and), || (or) and ! (not). In annotation-style aspects we can also give an expression a name by putting it on an empty method annotated with @Pointcut, then refer to it by that method's name. Named pointcuts are easier to read, can be documented and tested, and can be shared from a central class across several aspects.
So serviceLayer() && audited() advises only audited methods inside the service packages, and the second advice excludes toString() so that log statements printing a client do not get timed. When pointcuts live in a separate class, other aspects refer to them by their fully qualified name, such as com.acme.aop.AcmeAspects.audited().
6Follow-up questions
Why is execution(* com.acme.service..*(..)) also valid?
In that form the type and method parts are merged: com.acme.service..* means any type in the package tree, and the final * followed by (..) is read as the method. Both forms appear in documentation; the explicit *.*(..) form is easier for readers to parse.
Does bean(*Client) apply to methods the bean inherits?
Yes. It selects every method execution on that bean that the proxy can intercept, including inherited public methods. The usual proxy limits still apply, so private, final and self-called methods are not advised.
How would I test that a pointcut matches what I expect?
A quick way is AspectJExpressionPointcut: set the expression, then call matches(method, targetClass) for a few methods in a unit test. An integration test that calls a real bean and checks the advice's effect covers the bean() designator, which needs a running context.
7Conclusion
In this answer, we wrote three pointcuts. execution(public * com.acme.service..*.*(..)) matches public methods in the package and all sub-packages, where the double dot is the part that brings in sub-packages. @annotation(com.acme.Audited) matches methods carrying a runtime-retained annotation. bean(*Client) matches every method of beans whose Spring bean name ends with Client, and works only in Spring AOP. We combined them with &&, || and ! and named them with @Pointcut methods for reuse.
Open with
For the first one I would write execution(public * com.acme.service..*.*(..)). Reading left to right: public methods, any return type, any type in com.acme.service or any sub-package, which is what the double dot gives you, any method name, and any parameters, which is the (..) at the end.
Then, if they want more
With a single dot it would only match types directly in that package. For the second I would use @annotation(com.acme.Audited), which matches method executions where the method itself is annotated, and the annotation needs runtime retention. If the advice needs the annotation's attributes, I can bind it with @annotation(audited) and an Audited parameter on the advice method.
For the third, bean(*Client) matches all methods of beans whose Spring bean name ends in Client. It matches on the bean name, not the class name, and it is specific to Spring AOP, so it would not work if the aspect were woven with AspectJ.
Then I can combine these with &&, || and !, and I would give each one a name with an empty method annotated @Pointcut, for example serviceLayer() and audited(), so advice can say serviceLayer() && audited() and other aspects can reuse them by their qualified names.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Write pointcut expressions for: (1) all public methods in classes in com.acme.service...": https://scrivio-interview-library.netlify.app/spring-boot/aop/4a1153b58c/