concept pointcut in category spring

appears as: pointcut, pointcut, The pointcut
Spring in Practice

This is an excerpt from Manning's book Spring in Practice.

Next is the AOP configuration section . You want to define an aspect, which requires both a pointcut and an advice. You already have the advice, so you need to create the pointcut and the aspect. You define the pointcut at using the AspectJ pointcut notation. Then you define the aspect at , which in Spring AOP you implement as an advisor, using both the advice and pointcut you created earlier.

Using <aop:config> will trigger Spring AOP’s powerful autoproxying mechanism. We won’t get into all the details because you don’t need them here, but essentially autoproxying automatically wraps beans with proxies as required by the aspects you define explicitly. In this case, autoproxying proxies the message service and applies the guard-list aspect to the MessageServiceImpl methods specified in the pointcut.

The AnnotationGuardListSource gives the GuardListInterceptor a way to get a guard list according to the method being invoked. But you’ll need to create a custom pointcut class as well. You didn’t have to do that in recipe 14.3, but you have to do it here. The reason has to do with Spring’s autoproxy mechanism, which you used implicitly in recipe 14.3 and which you’ll use again here. In a nutshell, autoproxying figures out which advisors (aspects) apply to which beans by examining advisor pointcuts. In recipe 14.3 you used a pointcut expression to select the desired joinpoints, but here the placement of the @GuardedBy annotation determines the joinpoints. You have to give the autoproxying mechanism a pointcut that knows whether a given method has an associated guard list, indicating that a proxy must be created.