静态代理 package com.test.staticProxy; public interface IUsersService { public void insert(); } package com.test.staticProxy; //目标类 public class UsersService implements IUsersService { @Override public void insert() { System.out.println("添加用户"); } } package com.test.staticProxy; import java.util.Date; //代理类 public class UsersServiceProxy implements IUsersService { //在代理类中存放一个目标类对象 private IUsersService usersService=new UsersService(); @Override public void insert() { System.out.println("添加开始前:"+new Date()); usersService.insert(); System.out.println("添加结束后:"+new Date()); } } 测试 package com.test.staticProxy; import org.junit.Test; public class TestStaticProxy { @Test public void test() { IUsersService usersService=new UsersServiceProxy(); usersService.insert(); } }