One
1. Other classes as in the previous example, the audience analogy using the @aspectj method of the label and Pointcut,before and other definitions
1 PackageCom.springinaction.springidol;2 3 Public classAudience {4 Public voidTakeseats () {//<co id= "Co_takeseats"/>5System.out.println ("The audience is taking their seats.");6 }7 8 Public voidTurnoffcellphones () {//<co id= "Co_turnoffcellphones"/>9System.out.println ("The audience is turning off their cellphones");Ten } One A Public voidApplaud () {//<co id= "Co_applaud"/> -System.out.println ("Clap clap clap clap Clap"); - } the - Public voidDemandrefund () {//<co id= "Co_demandrefund"/> -System.out.println ("Boo! We Want our Money back! "); - } +}
2.xml (because you define slices directly in XML, so don't write <AOP:ASPECTJ-AUTOPROXY>)
(1)
1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"5Xsi:schemalocation= "Http://www.springframework.org/schema/beans6http//www.springframework.org/schema/beans/spring-beans.xsd7http//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP8http//www.springframework.org/schema/aop/spring-aop.xsd ">9 Ten<bean id= "Eddie" One class= "Com.springinaction.springidol.Instrumentalist" > A<property name= "Instrument" > -<beanclass= "Com.springinaction.springidol.Guitar"/> -</property> the</bean> - -<!--<start id= "Audience_bean"/>--> -<bean id= "Audience" + class= "Com.springinaction.springidol.Audience"/> -<!--<end id= "Audience_bean"/>--> + A<!--<start id= "Audience_aspect"/>--> at<aop:config> -<aop:aspect ref= "Audience" ><!--<co id= "Co_refaudiencebean"/>--> - -<aop:before pointcut= -"Execution (* com.springinaction.springidol.Performer.perform (..))" -method= "Takeseats"/> <!--<co id= "Co_beforepointcut"/>--> in -<aop:before pointcut= to"Execution (* com.springinaction.springidol.Performer.perform (..))" +method= "Turnoffcellphones"/> <!--<co id= "Co_beforepointcut2"/>--> - the<aop:after-returning pointcut= *"Execution (* com.springinaction.springidol.Performer.perform (..))" $Method= "Applaud"/> <!--<co id= "Co_afterpointcut"/>-->Panax Notoginseng -<aop:after-throwing pointcut= the"Execution (* com.springinaction.springidol.Performer.perform (..))" +method= "Demandrefund"/> <!--<co id= "Co_afterthrowingpointcut"/>--> A the</aop:aspect> +</aop:config> -<!--<end id= "Audience_aspect"/>--> $ $</beans>
(2) or
1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"5Xsi:schemalocation= "Http://www.springframework.org/schema/beans6http//www.springframework.org/schema/beans/spring-beans.xsd7http//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP8http//www.springframework.org/schema/aop/spring-aop.xsd ">9 Ten<bean id= "Eddie" One class= "Com.springinaction.springidol.Instrumentalist" > A<property name= "Instrument" > -<beanclass= "Com.springinaction.springidol.Guitar"/> -</property> the</bean> - -<!--<start id= "Audience_bean"/>--> -<bean id= "Audience" + class= "Com.springinaction.springidol.Audience"/> -<!--<end id= "Audience_bean"/>--> + A<!--<start id= "Audience_aspect"/>--> at<aop:config> -<aop:aspect ref= "Audience" > -<aop:pointcut id= "Performance" expression= -"Execution (* com.springinaction.springidol.Performer.perform (..))" -/> <!--<co id= "Co_defpointcut"/>--> - in<Aop:before -pointcut-ref= "Performance" tomethod= "Takeseats"/> <!--<co id= "Co_refpointcut"/>--> +<Aop:before -pointcut-ref= "Performance" themethod= "Turnoffcellphones"/> <!--<co id= "Co_refpointcut"/>--> *<aop:after-returning $pointcut-ref= "Performance"Panax NotoginsengMethod= "Applaud"/> <!--<co id= "Co_refpointcut"/>--> -<aop:after-throwing thepointcut-ref= "Performance" +method= "Demandrefund"/> <!--<co id= "Co_refpointcut"/>--> A</aop:aspect> the</aop:config> +<!--<end id= "Audience_aspect"/>--> - $<!--<start id= "Audience_around_advice"/>--> $<aop:config> -<aop:aspect ref= "Audience" > -<aop:pointcut id= "Performance2" expression= the"Execution (* com.springinaction.springidol.Performer.perform (..))" -/>Wuyi the<Aop:around -pointcut-ref= "Performance2" WuMethod= "watchperformance ()"/> <!--<co id= "Co_around"/>--> -</aop:aspect> About</aop:config> $<!--<end id= "Audience_around_advice"/>--> -</beans>
SPRING in ACTION 4th Note-fourth chapter aspect-oriented spring-006-defining slices using XML