VMware offers training and certification to turbo-charge your progress.Learn more
Spring 2.5 features a new pointcut designator -- bean() that allows selecting join points in beans with a matching name pattern. Now it is possible to use the auto-proxy mechanism along with Spring-AspectJ integration to select a specific bean even when there are more than one beans of a type. Earlier, you could use BeanNameAutoProxyCreator to achieve a similar result; however, that mechanism didn't work with Schema-style or @AspectJ aspects.
Besides selecting a specific bean, this pointcut designator offers two interesting ways to select beans if you follow an appropriate naming convention:
Figure 1: Selecting horizontal and vertical slices of beans based on their names using bean() pointcutsThis pointcut represents a Spring-specific extension to the AspectJ pointcut expression language and as such is useful only in a Spring-based application. The name-pattern follows the AspectJ matching rules for a name pattern with '*' being the only allowed wildcard. Here is a table showing a few example pointcuts and beans selected by them.
|Pointcut||Join points selected in|
|bean(accountRepository)||The bean named "accountRepository"|
|!bean(accountRepository)||Any bean except the "accountRepository" bean|
|bean(account*)||Any bean with name starting in "account"|
|bean(*Repository)||Any bean with name ending in "Repository"|
|bean(accounting/showaccount)||The bean named accounting/showaccount (designating, say, a controller handling that URL)|
|bean(accounting/*)||Any bean whose name starts with "accounting/" (designating, say, any controller handling accounting-related URLs)|
|bean(accounting/*/edit)||Any bean whose name starts with "accounting/" and ends with "/edit" (designating, say, any controller handling the edit operation functionality related to accounting)|
|bean(*dataSource) || bean(*DataSource)||Any bean whose name ends with either "dataSource" or "DataSource"|
|bean(service:name=monitoring)||The bean named "service:name=monitoring"|