public interface Service {
public void add();
public void update();
}
package com.springmvc.service;
public class AService implements Service{
@Override
public void add() {
System.out.println("AService add>>>>>>>>>>>>>>>>>>");
}
@Override
public void update() {
System.out.println("AService update>>>>>>>>>>>>>>>");
}
}
package com.springmvc.service;
public class AService implements Service{
@Override
public void add() {
System.out.println("AService add>>>>>>>>>>>>>>>>>>");
}
@Override
public void update() {
System.out.println("AService update>>>>>>>>>>>>>>>");
}
}
package com.springmvc.test;
import java.lang.reflect.Proxy;
import com.springmvc.service.AService;
import com.springmvc.service.Service;
public class Test {
public static void main(String[] args) {
Service aService = new AService();
MyInvocationHandler handler = new MyInvocationHandler(aService);
Service aServiceProxy = (Service) Proxy.newProxyInstance(aService.getClass().getClassLoader(),
aService.getClass().getInterfaces(), handler);
aServiceProxy.add();
aServiceProxy.update();
}
}
转载于:https://my.oschina.net/projerry/blog/807399