切入点表达式execution()
用于描述方法 【掌握】
语法:execution(修饰符 返回值 包.类.方法名(参数) throws异常)
修饰符,一般省略
public 公共方法
任意
返回值,不能省略
void 返回没有值
String 返回值字符串
任意
包,[省略]
com.gyf.crm 固定包
com.gyf.crm..service crm包下面子包任意 (例如:com.gyf.crm.staff.service)
com.gyf.crm.. crm包下面的所有子包(含自己)
com.gyf.crm..service.. crm包下面任意子包,固定目录service,service目录任意包
类,[省略]
UserServiceImpl 指定类
Impl 以Impl结尾
User 以User开头
任意
方法名,不能省略
addUser 固定方法
add 以add开头
Do 以Do结尾
任意
(参数)
() 无参
(int) 一个整型
(int ,int) 两个
(..) 参数任意
throws ,可省略,一般不写。
案例1:
execution( com.gyf.crm..service...(..))
案例2:或
<aop:pointcut expression=”execution( com.gyf.crm.service..*(..)) ||
execution( com.gyf.Do.*(..))” id=”myPointCut”/>
示例:
<!-- 配置UserService--><bean id="userService" class="com.gyf.service.UserServiceImpl"></bean><bean id="studentService" class="com.gyf.service.StudentService"></bean><!-- 配置切面类对象--><bean id="myAspect" class="com.gyf.aspect.MyAspect"></bean><!-- 全自动AOP配置1.在bean中配置aop约束2.配置aop:conifg内容,把切入点和通知结合proxy-target-class:使用cglib实现代理expression 表达式:*任意execution(* com.gyf.service.*. * (..))返回值 包名 类名 方法名 参数--><aop:config proxy-target-class="true"><!-- 切入点:expression:表达式每个service的方法前面都开启事务和结束事务AOP:用于事务配置&日志记录--><aop:pointcut id="myPointcut" expression="execution(* com.gyf.service.*.*(..))"/><!-- 通知 关联 切入点--><aop:advisor advice-ref="myAspect" pointcut-ref="myPointcut"></aop:advisor></aop:config>
