Waiter类:
public class Waiter {
public void greetTo(String name) {
System.out.println("waiter greet to "+name+"...");
}
public void serveTo(String name){
System.out.println("waiter serving "+name+"...");
}
}
TestAdvisorByProxyFactory类:
public class TestAdvisorByProxyFactory {
public static void main(String[] args) {
Waiter waiterTarget = new Waiter();
BeforeAdvice advice = new GreetingBeforeAdvice();
Advisor advisor = new GreetingAdvisor();
ProxyFactory pf = new ProxyFactory();
pf.setOptimize(true);
pf.addAdvice(advice);
pf.addAdvisor(advisor);
Waiter waiter = (Waiter) pf.getProxy();
waiter.greetTo("john");
waiter.serveTo("john");
}
}
运行时候报错:
Exception in thread "main" org.springframework.aop.framework.AopConfigException: TargetSource cannot determine target class: Either an interface or a target is required for proxy creation.
at org.springframework.aop.framework.DefaultAopProxyFactory.createAopProxy(DefaultAopProxyFactory.java:56)
at org.springframework.aop.framework.ProxyCreatorSupport.createAopProxy(ProxyCreatorSupport.java:105)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:96)
at cn.zw.test.advisor.TestAdvisorByProxyFactory.main(TestAdvisorByProxyFactory.java:20)
怎么修改才能运行呢?