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
下載鏈接自行百度即可。