Spring对AOP的支持
*如果目标类实现了接口,默认采用JDK动态代理来实现AOP
*如果目标类没有实现接口,必须添加CGLIB支持,Spring会自动在JDK和CGLIB代理之间切换
*如果目标类实现了接口,可以定义让Spring强制使用CGLIB代理
如何强制使用CGLIB代理实现AOP
*将<aop:config>定义为<aop:config proxy-target-class="true">
并且引入CGLIB包;Spring_home\lib\cglib\*.jar
代理模式示意:
public interface UserManager(){
public void addUser();
}
public class UserManagerImpl implements UserManeger{
public void addUser(){
System.out.println("================");
}
}
public class UsermanagerImplProxy implements UserManager{
private UsermanagerImpl usermanagerImpl
public void addUser(){
checkSecurity();
usermanagerImpl.addUser();
}
privatecheckSecurity(){
//
}
}
|
|