Spring AOP简单例子

-------------------

class Dog{

    publi void chi(){

      syso("Dog吃----");

     }

     public void jiao(){

      syso("Dog叫----");

    }

}

----

class Cat{

  publi void chi(){

      syso("Cat吃----");

     }

     public void jiao(){

      syso("Cat叫----");

    }

}

公共方法-----------------------------------------

class Gape implements MethodBeforeAvice{

    ....  before(...){

      syso("张嘴");

   }

}

applicationContext.xml-----------------------------

<beans>

   <bean id="tomcat" class="Cat类路径"></>

   <bean id="snoopy" class="Dog类路径"></>

  

   <bean id="niurouAvice" class="Gape类路径"></>

   <!--  -->

   <bean id="jianiurou" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">

      <property name="Avice" ref="niurouAvice"></>

      <property name="pattern" value="....Dog.(chi | jiao)"></>//向Dog类的chi()和jiao()方法中注入Gape

   </>

   

   <bean id="newSnoopy" class="org.springframework.aop.framework.ProxyFactoryBean">

      <property name="taget" ref="snoopy"></> 

      <property name="intercephalicName">

         <list>

                <value>jianiurou</>

          </>

      </>

   </>

 

</>

Test------------------

class Test{

  main===>

  applicationContext app=new ClassPathXmlapplicationContext("applicationContext.xml路径");

 

 

 

}

 

你可能感兴趣的:(spring,AOP,tomcat,bean,xml)