concept bean in category aspectj

appears as: bes, bes, bean, be, The be, be
AspectJ in Action, Second Edition

This is an excerpt from Manning's book AspectJ in Action, Second Edition.

You can use AOP along with an underlying framework. In such an arrangement, the core framework deals with the target problem and lets aspects deal with crosscutting concerns. For example, the core Spring Framework deals with dependency injection for configuration and enterprise service abstraction to isolate beans from the underlying infrastructure details, while employing AOP to deal with crosscutting concerns such as transaction management and security.

Bean is the most fundamental concept in Spring. An application is a composition of beans created as per the configuration instructions. Beans are also the objects that can be proxied to apply aspects. It’s therefore appropriate that there be a way to select specific beans based on their identifiers. Starting with version 2.5, Spring offers a new pointcut designator: bean(<name-pattern>). The name-pattern follows the AspectJ matching rules for a name pattern with * being the only allowed wildcard. This pointcut represents a Spring-specific extension to the AspectJ expression language and as such is useful only with Spring AOP.

This pointcut designator offers two interesting ways to select beans if you follow an appropriate naming convention:

  • Selecting a vertical slice of beans— If you follow a convention where bean names include a string indicating their role from the business perspective, a bean() pointcut can select beans based on business functionality. For example, you can use the bean(inventory*) pointcut to select all inventory related beans such as inventoryRepository, inventoryService, and inventoryController.
  • Selecting a horizontal slice of beans— If you follow a convention where bean names include a string indicating their role from the architectural perspective, a bean() pointcut can select beans based on their architectural role. For example, you can use bean(*Repository) to select all repository beans. Without the bean() pointcut, you have to rely on the package structure or type-based pointcuts, which can sometimes be too restrictive.
  • Figure 9.6. Selecting horizontal and vertical slices of beans based on their names using the bean() pointcut designator