Spring 3.x企业应用开发实战(10)----AOP切面
1、静态普通方法名匹配切面
StaticMethodMatcherPointcutAdvisor代表一个静态方法匹配切面。
package com.smart.advisor;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class SpringAdvisorTest {@Testpublic void testAdvisor(){String configPath="com/smart/advisor/beans4.xml";ApplicationContext ctx=new ClassPathXmlApplicationContext(configPath);Waiter waiter=(Waiter)ctx.getBean("waiterTarget");Seller seller=(Seller)ctx.getBean("sellerTarget");waiter.serveTo("John");waiter.greetTo("John");seller.greetTo("Tom");}}
得到的结果是:
Waiter serving John...
com.smart.advisor.Waiter.greetTo
How are you ! Mr.John.
Waiter greet to John...
com.smart.advisor.Seller.greetTo
How are you ! Mr.Tom.
Seller greet to Tom...