Skip to content

Commit a22be8b

Browse files
committed
adjust
1 parent de1f6f8 commit a22be8b

File tree

7 files changed

+24
-60
lines changed

7 files changed

+24
-60
lines changed

java-knowledge-base/src/main/java/base/agent/origin/IUserDao.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

java-knowledge-base/src/main/java/base/agent/origin/UserDao.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

java-knowledge-base/src/main/java/base/agent/origin/UserDaoWithoutInterface.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

java-knowledge-base/src/main/java/base/agent/cglibproxy/CGlibProxyFactory.java renamed to java-knowledge-base/src/main/java/base/agent/proxy/cglib/CGlibProxyFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package base.agent.cglibproxy;
1+
package base.agent.proxy.cglib;
22

33
import net.sf.cglib.proxy.Enhancer;
44
import net.sf.cglib.proxy.MethodInterceptor;

java-knowledge-base/src/main/java/base/agent/jdkproxy/JDKProxyFactory.java renamed to java-knowledge-base/src/main/java/base/agent/proxy/jdk/JDKProxyFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package base.agent.jdkproxy;
1+
package base.agent.proxy.jdk;
22

33
import java.lang.reflect.InvocationHandler;
44
import java.lang.reflect.Method;

java-knowledge-base/src/main/java/base/agent/staticproxy/StaticUserDaoProxy.java renamed to java-knowledge-base/src/main/java/base/agent/proxy/staticagent/StaticUserDaoProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package base.agent.staticproxy;
1+
package base.agent.proxy.staticagent;
22

3-
import base.agent.origin.IUserDao;
3+
import base.agent.target.IUserDao;
44

55
/**
66
* 静态代理类,继承接口,实现接口的方法
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package base.agent.test;
1+
package base.agent;
22

3-
import base.agent.cglibproxy.CGlibProxyFactory;
4-
import base.agent.jdkproxy.JDKProxyFactory;
5-
import base.agent.origin.IUserDao;
6-
import base.agent.origin.UserDao;
7-
import base.agent.origin.UserDaoWithoutInterface;
8-
import base.agent.staticproxy.StaticUserDaoProxy;
3+
import base.agent.proxy.cglib.CGlibProxyFactory;
4+
import base.agent.proxy.jdk.JDKProxyFactory;
5+
import base.agent.target.IUserDao;
6+
import base.agent.target.UserDao;
7+
import base.agent.target.UserDaoWithoutInterface;
8+
import base.agent.proxy.staticagent.StaticUserDaoProxy;
99
import org.junit.Test;
1010

1111
/**
@@ -37,33 +37,28 @@ public void testJdkProxyFactoryWithInterface() {
3737
JDKProxyFactory jdkProxyFactory = new JDKProxyFactory(targetWithInterface);
3838
// 注意,只能返回接口而不是具体实现类,否则报错,参见testJdkProxyFactoryWithoutInterface方法
3939
IUserDao iTarget = (IUserDao) jdkProxyFactory.getProxyInstance();
40+
System.out.println("ProxyObj = " + iTarget.getClass().toString());
4041
iTarget.save();
4142
}
4243

44+
@Test
45+
public void testCGlibProxyFactoryWithoutInterface() {
46+
CGlibProxyFactory cGlibProxyFactory = new CGlibProxyFactory(targetWithoutInterface);
47+
UserDaoWithoutInterface pTarget = (UserDaoWithoutInterface) cGlibProxyFactory.getProxyInstance();
48+
System.out.println("ProxyObj = " + pTarget.getClass().toString());
49+
pTarget.save();
50+
}
51+
4352
/**
44-
* 测试JDK静态代理实现
53+
* 测试JDK静态代理实现无接口的对象,会报错
4554
*/
4655
@Test
4756
public void testJdkProxyFactoryWithoutInterface() {
4857
//jdk动态代理
4958
JDKProxyFactory jdkProxyFactory = new JDKProxyFactory(targetWithoutInterface);
5059
// 注意,只能返回接口而不是具体实现类,否则报如下错误
51-
UserDaoWithoutInterface iTarget = (UserDaoWithoutInterface) jdkProxyFactory.getProxyInstance();
52-
iTarget.save();
53-
}
54-
55-
@Test
56-
public void testCGlibProxyFactoryWithoutInterface(){
57-
CGlibProxyFactory cGlibProxyFactory = new CGlibProxyFactory(targetWithoutInterface);
58-
UserDaoWithoutInterface dao = (UserDaoWithoutInterface) cGlibProxyFactory.getProxyInstance();
59-
dao.save();
60+
UserDaoWithoutInterface pTarget = (UserDaoWithoutInterface) jdkProxyFactory.getProxyInstance();
61+
System.out.println("ProxyObj = " + pTarget.getClass().toString());
62+
pTarget.save();
6063
}
61-
62-
@Test
63-
public void testCGlibProxyFactoryWithInterface(){
64-
CGlibProxyFactory cGlibProxyFactory = new CGlibProxyFactory(targetWithInterface);
65-
UserDao dao = (UserDao) cGlibProxyFactory.getProxyInstance();
66-
dao.save();
67-
}
68-
6964
}

0 commit comments

Comments
 (0)