aop
<!-- 扫描bean -->
<context:component-scan base-package="com.spring.aop"></context:component-scan>
<!-- spring的aop实现 -->
<aop:config>
<!-- 定义切点和切面 也就是类的哪些方法被代理 -->
<aop:pointcut expression="execution(* com.spring.aop.People.walk(..))" id="peopleCut"/>
<!-- 定义通知 advice-ref引用的是通知的类 通知的类可以继承前置通知和后置通知的接口
<aop:pointcut expression="execution(* *..*.ChineseWalk.eat(..))" id="eatPointCut"/>
前置通知 对应接口 org.springframework.aop.MethodBeforeAdvice
后置通知 对应接口 org.springframework.aop.AfterAdvice
返回通知 对应接口 org.springframework.aop.AfterReturningAdvice
异常通知 对应接口 org.springframework.aop.ThrowsAdvice
环绕通知 对应接口 org.aopalliance.intercept.MethodInterceptor
-->
<aop:advisor advice-ref="peopleAdvise" pointcut-ref="peopleCut"/>
</aop:config>
aspectj
<!-- 扫描bean -->
<context:component-scan base-package="com.spring.aspectj"></context:component-scan>
<!-- spring的aop实现
项目的包结构
com.公司名.项目名称.模块名称 (action,service,dao)
事物的拦截 在service层
*..* 代表多个包名
最后一个*代表方法名称
最开始的*代表返回值
* com.*..*.service.*.*(..)
返回值 多个包.类名.方法名(参数)
-->
<aop:config>
<!-- 定义切点和切面 也就是类的哪些方法被代理 -->
<aop:aspect ref="peopleAdvise">
<!-- pointcut必须定义在aop:aspect 之中 -->
<aop:pointcut expression="execution(* com.spring.aspectj.People.walk(..))" id="peopleCut"/>
<!-- 前置通知 -->
<aop:before method="before" pointcut-ref="peopleCut"/>
<!-- 后置通知 -->
<aop:after method="after" pointcut-ref="peopleCut"/>
<!-- 后置返回通知 -->
<aop:after-returning method="afterReturning" pointcut-ref="peopleCut"/>
<!-- 环绕通知 -->
<aop:around method="invoke" pointcut-ref="peopleCut"/>
<!-- 异常通知 -->
<aop:after-throwing method="error" pointcut-ref="peopleCut"/>
</aop:aspect>
</aop:config>