In some scenarios, facets can only be defined based on XML.
"Spring's definition of slice attempt"
1, the definition of thetangent plane (the first is to have a corresponding class ...) Obviously more trouble than a note-based)
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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 "> <!--Enable ASPECTJ automatic proxy does not start also can use??? - <Aop:aspectj-autoproxy/> <BeanID= "Audience"class= "concert." Audience " /> <Aop:config> <Aop:aspectref= "Audience"> <Aop:beforeMethod= "Silencecellphones"pointcut= "Execution (* concert). Performance.perform (..)) " /> <Aop:beforeMethod= "Takeseats"pointcut= "Execution (* concert). Performance.perform (..)) " /> <aop:after-returningMethod= "Applause"pointcut= "Execution (* concert). Performance.perform (..)) " /> <aop:after-throwingMethod= "Demandrefund"pointcut= "Execution (* concert). Performance.perform (..)) " /> </Aop:aspect> </Aop:config> <BeanID= "Theshow"class= "concert." Theshow " /></Beans>
Use <aop:pointcut> to define a named Pointcut
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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 "> <!--Enable ASPECTJ automatic proxy does not start also can use??? - <Aop:aspectj-autoproxy/> <BeanID= "Audience"class= "concert." Audience " /> <Aop:config> <Aop:aspectref= "Audience"> <Aop:pointcutID= "Performance"expression= "Execution (* concert). Performance.perform (..)) " /> <Aop:beforeMethod= "Silencecellphones"Pointcut-ref= "Performance" /> <Aop:beforeMethod= "Takeseats"Pointcut-ref= "Performance" /> <aop:after-returningMethod= "Applause"Pointcut-ref= "Performance" /> <aop:after-throwingMethod= "Demandrefund"Pointcut-ref= "Performance" /> </Aop:aspect> </Aop:config> <BeanID= "Theshow"class= "concert." Theshow " /></Beans>
Modify to Surround notification:
PackageConcert;ImportOrg.aspectj.lang.ProceedingJoinPoint;Importorg.aspectj.lang.annotation.*; Public classAudience { Public voidperformance () {} Public voidwatchperformance (proceedingjoinpoint JP) {Try{System.out.println ("Silencing cell Phones"); System.out.println ("Taking seats"); Jp.proceed (); System.out.println ("Clap clap clap!!! AP CLAP!!! AP CLAP!!! AP CLAP!!! "); } Catch(Throwable e) {System.out.println ("Demanding a refund"); } }}
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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 "> <Aop:aspectj-autoproxy/> <BeanID= "Audience"class= "concert." Audience " /> <Aop:config> <Aop:aspectref= "Audience"> <Aop:pointcutID= "Performance"expression= "Execution (* concert). Performance.perform (..)) " /> <Aop:aroundMethod= "Watchperformance"Pointcut-ref= "Performance" /> </Aop:aspect> </Aop:config> <BeanID= "Theshow"class= "concert." Theshow " /></Beans>
2. Test the defined Facets
PackageConcert;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; Public classMain { Public Static voidMain (string[] args) {//Import ConfigurationApplicationContext CTX =NewClasspathxmlapplicationcontext ("Concert-config.xml"); Performance Performance= (performance) Ctx.getbean ("Theshow"); Performance.perform (); }}
Everything is OK ...
Spring's definition slice attempt (XML-based)