SPRING-AOP Example

Source: Internet
Author: User

Specific cases on GitHub, mostly jar packages on top

Https://github.com/guoyansi/spring-aop-example

Knights.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:tx= "Http://www.springframework.org/schema/tx"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-bea Ns.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring- Context.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc- 3.2.xsd http://www.springframework.org/schema/tx Http://www.springframework.org/schema/tx/spring-tx. xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd ">        <BeanID= "Knight"class= "P1." Braveknight ">            <Constructor-argref= "Quest" />        </Bean>        <BeanID= "Quest"class= "P1." Slaydragonquest "></Bean>                <BeanID= "Minstrel"class= "P1." Minstrel "></Bean>                <Aop:config>            <Aop:aspectref= "Minstrel">                <Aop:pointcutID= "Embark"expression= "Execution (* *.embarkonquest (..))" />                <Aop:beforePointcut-ref= "Embark"Method= "Singbeforequest"/>                <Aop:afterPointcut-ref= "Embark"Method= "Singafterquest"/>            </Aop:aspect>        </Aop:config>              </Beans>

Iquest.java

 Package P1; /**  */Publicinterface  IQuest    {void  embark ();}

Iknight.java

 Package P1;  Public Interface iknight {    void  embarkonquest ();}

Braveknight.java

 Package P1; /**  */Publicclassimplements     iknight{Private IQuest Quest;          Public Braveknight (IQuest Quest) {        this.quest=Quest;            }    @Override    publicvoid  embarkonquest () {        quest.embark ();    }    }

Slaydragonquest.java

 Package P1;  Public class Implements iquest{    @Override    publicvoid  embark () {        System.out.println (" Slaydragonquest embark ... ");             }

Minstrel.java

 package   P1;  public  class   Minstrel { void   Singbeforequest () {System.out.println (" Before adventure ... ");  public  void   Singafterquest () {System.out.println ( "After adventure ..." 
 package   P1;  import   Org.springframework.context.ApplicationContext;  import   Org.springframework.context.support.ClassPathXmlApplicationContext;  public  class   Run { public  static  void   Main (string[] args) {applicationcontext context  =new  classpathxmlapplicationcontext (" Classpath*:knights.xml ");        Iknight Knight  = (iknight) Context.getbean ("Knight" );    Knight.embarkonquest (); }}

To execute the result of run:

The above is a complete example. If there is no Commons-logging.jar

The red lettering on the console will not output, and there will be exceptions.

If there is no Aopalliance.jar:

nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

If there is no Aspectjweaver.jar

nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

SPRING-AOP Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.