/spring_03/src/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 目标类 (有切入点 有被增强的方法save) -->
<bean id="person" class="cn.itcast.domain.Person"></bean>
<!-- 切面类(有通知/增强 有增强方法) -->
<bean id="myAspect" class="cn.itcast.aspectj.MyAspect"></bean>
<!-- 配置织入(增强方法和被增强方法集成在一起) -->
<aop:config>
<aop:aspect ref="myAspect">
<!-- 定义切入点 -->
<aop:pointcut expression="execution(void cn.itcast.domain.Person.save())" id="pointcut1"/>
<aop:pointcut expression="execution(void cn.itcast.domain.Person.delete())" id="pointcut2"/>
<aop:pointcut expression="execution(* cn.itcast.domain.Person.up*(..))" id="pointcut3"/>
<aop:pointcut expression="execution(* cn.itcast.domain.*.find(..))" id="pointcut4"/>
<!-- 原始方式 -->
<!-- <aop:before method="beforeMethod" pointcut="execution(void cn.itcast.domain.Person.save())"/>
<aop:after-returning method="aftereturningMethod" pointcut="execution(void cn.itcast.domain.Person.save())"/> -->
<!--便捷方式 -->
<aop:before method="beforeMethod" pointcut-ref="pointcut1"/>
<aop:after-returning method="aftereturningMethod" pointcut-ref="pointcut1"/>
<aop:after-returning method="aftereturningMethod" pointcut-ref="pointcut2"/>
<aop:around method="aroundMethod" pointcut-ref="pointcut3"/>
<aop:after-throwing method="throwingMethod" pointcut-ref="pointcut4"/>
<aop:after method="afterMethod" pointcut-ref="pointcut4"/>
</aop:aspect>
</aop:config>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 目标类 (有切入点 有被增强的方法save) -->
<bean id="person" class="cn.itcast.domain.Person"></bean>
<!-- 切面类(有通知/增强 有增强方法) -->
<bean id="myAspect" class="cn.itcast.aspectj.MyAspect"></bean>
<!-- 配置织入(增强方法和被增强方法集成在一起) -->
<aop:config>
<aop:aspect ref="myAspect">
<!-- 定义切入点 -->
<aop:pointcut expression="execution(void cn.itcast.domain.Person.save())" id="pointcut1"/>
<aop:pointcut expression="execution(void cn.itcast.domain.Person.delete())" id="pointcut2"/>
<aop:pointcut expression="execution(* cn.itcast.domain.Person.up*(..))" id="pointcut3"/>
<aop:pointcut expression="execution(* cn.itcast.domain.*.find(..))" id="pointcut4"/>
<!-- 原始方式 -->
<!-- <aop:before method="beforeMethod" pointcut="execution(void cn.itcast.domain.Person.save())"/>
<aop:after-returning method="aftereturningMethod" pointcut="execution(void cn.itcast.domain.Person.save())"/> -->
<!--便捷方式 -->
<aop:before method="beforeMethod" pointcut-ref="pointcut1"/>
<aop:after-returning method="aftereturningMethod" pointcut-ref="pointcut1"/>
<aop:after-returning method="aftereturningMethod" pointcut-ref="pointcut2"/>
<aop:around method="aroundMethod" pointcut-ref="pointcut3"/>
<aop:after-throwing method="throwingMethod" pointcut-ref="pointcut4"/>
<aop:after method="afterMethod" pointcut-ref="pointcut4"/>
</aop:aspect>
</aop:config>
</beans>