Spring_增强的CGLIB代理基本实现

package ProxyShows;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class cacufun {//implements caCu{
	//@Override
	public int add(int i,int j) {
		return i+j;
	}
@Override
	public String toString() {
		return "cacufun [getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString()
				+ "]";
	}
public static void main(String agrs[]) {
	ApplicationContext ioc=new ClassPathXmlApplicationContext("apContext.xml");
	cacufun test=ioc.getBean(cacufun.class);
	System.out.println(result);
	System.out.println(test.toString()+"\n"+test.getClass());
}
}
cacufun [getClass()=class ProxyShows.cacufun, hashCode()=1047934137, toString()=ProxyShows.cacufun@3e7634b9]
class ProxyShows.cacufun$$EnhancerBySpringCGLIB$$8e599bd6

结论:这里去掉了对接口的实现,直接使用独立的类来进行动态代理,看出代理类变化了,使用的是Spring的增强的代理类CGLIB,可以对于未实现任何接口的类进行动态代理,方便了我们的使用。

需要导入:com.springsource.net.sf.cglib-sources-2.2.0.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
下载链接自行百度即可。

发布了7 篇原创文章 · 获赞 0 · 访问量 67

猜你喜欢

转载自blog.csdn.net/weixin_43458072/article/details/102568711