Spring AOP 用户可能会经常使用 execution
pointcut designator。执行表达式的格式如下:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)
除了返回类型模式(上面代码片断中的ret-type-pattern),名字模式和参数模式以外,所有的部分都是可选的。
返回类型模式决定了方法的返回类型必须依次匹配一个连接点。
你会使用的最频繁的返回类型模式是 *
,它代表了匹配任意的返回类型。
一个全称限定的类型名将只会匹配返回给定类型的方法。名字模式匹配的是方法名。
你可以使用 *
通配符作为所有或者部分命名模式。
参数模式稍微有点复杂:()
匹配了一个不接受任何参数的方法,
而 (..)
匹配了一个接受任意数量参数的方法(零或者更多)。
模式 (*)
匹配了一个接受一个任何类型的参数的方法。
模式 (*,String)
匹配了一个接受两个参数的方法,第一个可以是任意类型,第二个则必须是String类型。
下面给出一些常见切入点表达式的例子。
-
任意公共方法的执行:
execution(public * *(..))
-
任何一个以“set”开始的方法的执行:
execution(* set*(..))
-
AccountService
接口的任意方法的执行:
execution(* com.xyz.service.AccountService.*(..))
-
定义在service包里的任意方法的执行:
execution(* com.xyz.service.*.*(..))
-
定义在service包或者子包里的任意方法的执行:
execution(* com.xyz.service..*.*(..))
分享到:
相关推荐
<aop:pointcut expression="execution(* com.spring.service..*(..))" id="pointCut"/>声明一个切入点,注意execution表达式的写法 <aop:before method="before" pointcut-ref="pointCut"/> aop前置通知 <aop:after ...
<aop:pointcut id="pointcut1" expression="execution(public void com.jas.aop.bean.PersonImpl.sayHello())"/> <aop:pointcut id="pointcut2" expression="execution(public void ...
expression="execution(* x.y.service.*Service.*(..))" /> <aop:pointcut id="noTxServiceOperation" expression="execution(* x.y.service.ddl.DefaultDdlManager.*(..))" /> <aop:advisor pointcut-ref=...
<aop:pointcut id="allManagerMethodPdm" expression="execution(* com.ccc.pdm..*.*(..))"/> <aop:advisor pointcut-ref="allManagerMethodPdm" advice-ref="txAdvicePdm"/> </aop:config> <!-- ibatis...
<aop:pointcut expression="execution(* com.org.service.*.*(..))" id="bussinessService" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService"/> </aop:config> <!-- 配置那个类那个...
在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点
<aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/> </aop:config> <!-- 通知配置 --> *" rollback-for="Exception"/> *" rollback-for="Exception"/> *" rollback-for="Exception"/...
<!--配置连接池--> <!--配置生产SqlSession对象的... <aop:pointcut id="pointcut" expression="execution(* com.itheima.service.impl.*.*(..))"/> <aop:advisor advice-ref="advice" pointcut-ref=
-- <aop:pointcut id="myPointcut" expression="execution(public * com.sbz.*.service.*.*(..))"/>--> <!-- <aop:advisor advice-ref="myAdvice" pointcut-ref="myPointcut"/>--> <!-- </aop:config>--> <!--AOP...
<aop:pointcut expression="execution(public * com.org.service.*.*(..))" id="bussinessService" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" /> </aop:config> <!-- 配置...
在 Spring实现 AOP面向切面编程, 是通过 @Aspect注解来实现切面的 使用场景 常见用于记录日志, 异常集中处理, 权限验证以及 Web参数有效验证等等 列子1 (演示基本过程 @Aspect @Component public class TestAspect ...
<aop:pointcut expression="execution(* com.direct.service.*.*(..))" id="transactionPointCut"/> <aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionPointCut"/> </aop:config> spring和...
<aop:pointcut expression="execution(public * com.org.core.service.*.*(..))" id="bussinessService" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" /> </aop:config> <!-- ...
<!-- - Application context definition for JPetStore's business layer. ... <aop:advisor pointcut="execution(* com.longxian.drp.manager.*.*(..))" advice-ref="txAdvice"/> </aop:config> </beans>
<aop:pointcut id="allServiceMethod" expression="execution(* com.cstp.service.*.*(..))"/> <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/> </aop:config> <!-- 新闻类型 --> ...
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd "> <!-- 自动扫描 --> *" /> <!-- 引入配置文件 --> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">...
<aop:pointcut id="adviceAspectPoint" expression="execution(* com.sample..*.*(..)) and @annotation(Aspect)" /> <aop:aspect ref="adviceAspect"> <aop:around method="execute" pointcut-...