SpringAOP中可以通过配置切点来指定在哪些方法上应用切面。切点可以通过表达式或者注解来定义。
使用表达式定义切点:可以在配置文件中使用<aop:pointcut>元素来定义切点,例如:<aop:pointcut id="myPointcut" expression="execution(* com.example.service.*.*(..))"/>上面的例子表示定义了一个切点myPointcut,它匹配了com.example.service包下的所有方法。
@Pointcut("execution(* com.example.service.*.*(..))")public void myPointcut() {}上面的例子定义了一个切点方法myPointcut(),它匹配了com.example.service包下的所有方法。
无论是使用表达式还是注解定义切点,都需要在配置文件中声明切点和切面的关系,例如:
<aop:config> <aop:aspect ref="myAspect"> <aop:pointcut id="myPointcut" expression="execution(* com.example.service.*.*(..))"/> <aop:before method="beforeAdvice" pointcut-ref="myPointcut"/> </aop:aspect></aop:config>上面的例子声明了一个切面myAspect,并指定了在myPointcut切点上应用beforeAdvice通知。


